Here is a example code on how to read Json format datas for web game development.
How to Read JSON Format Data with JAVA
/** * * @param result JSON string * @param name JSON array name * @param fields The fields contained in the JSON string * @return Returns a list of type List<Map<String,Object>>, Map<String,Object> corresponding to the structure "id": "1" */ public static List<Map<String, Object>> convertJSON2List(String result, String name, String[] fields) { List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); try { JSONArray array = new JSONObject(result).getJSONArray(name); for (int i = 0; i < array.length(); i++) { JSONObject object = (JSONObject) array.opt(i); Map<String, Object> map = new HashMap<String, Object>(); for (String str : fields) { map.put(str, object.get(str)); } list.add(map); } } catch (JSONException e) { Log.e("error", e.getMessage()); } return list; }
Read More:
- Java.sql.sqlexception: unable to read more data from socket
- [Solved] ImageIO.read(inputStream) Read .webp Format Image Error
- Java will convert Excel to list set or JSON, export excel file to local, excel import and export, easyexcel tool class
- Explicit and implicit conversion of Java data type
- [Solved] Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerExcepti
- JAVA 8: How to Convert List to Map
- [Solved] JAVA Web Error: startup failed due to previous errors
- Problems and causes of Java’s main function format (public static void main (string args()))
- [Solved] SpringBoot Date Convert Error: JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime`
- [Solved] JSON parse error: Cannot deserialize instance of `java.util.ArrayList<..> out of START_OBJECT token;
- [Solved] eureka Startup Error: Unable to start web … nested exception is org.springframework.boot.web.server.WebS
- [Solved] eureka Startup Error: Unable to start web … nested exception is org.springframework.boot.web.server.WebS
- [Solved] Read the resources resource and convert it to file error: java.io.filenotfoundexception
- How to Converte Java objects to jsonnode in Jackson (Four Methods)
- How to compare the time in two TimeStamp format?
- Java Web uses AJAX POST Method 405 terror [Solved]
- How to convert a Java string into a number (stringtonumber)
- How to Solve SSM JSON Chinese Messy Code Issue
- BeanDefinitionStoreException: Failed to read candidate component class probably due to a new Java
- JAVA Error Illegal access: this web application instance has been stopped already. Could not load net.sf