If you need to convert the String string into a json array, and as long as the value of a field in the string, the field is a string of the json array, such as the following json form
- {
- returnCode: "return code" ,
- returnMessage: "Returned error message" ,
- rowCount: "Number of rows returned" ,
- colCount: "Return the number of data columns" ,
- requestParams: "call parameters" ,
- requestTime: "receive request time" ,
- responseTime: "Return request result time" ,
- takeTime: "Time (in seconds)" ,
- DS:[
- {field name 1: "field value 1", field name 2: "field value 2", field name 3: "field value 3", ... },
- {field name 1: "field value 1", field name 2: "field value 2", field name 3: "field value 3", ... },
- {field name 1: "field value 1", field name 2: "field value 2", field name 3: "field value 3", ... },
- {field name 1: "field value 1", field name 2: "field value 2", field name 3: "field value 3", ... },
- {field name 1: "field value 1", field name 2: "field value 2", field name 3: "field value 3", ... }
- ]
- }
Get the value of the string DS and implement the code:
- JSONObject jsonObject = JSONObject.fromObject(str); //String to json object
- String data = jsonObject.getString( "DS" ); //Get DS content
- JSONArray jsonArray = JSONArray.fromObject(data); //And take out the DS content and convert it to a json array
- for ( int i = 0 ; i < jsonArray.size(); i++) { //traverse the contents of the json array
- JSONObject object = jsonArray.getJSONObject(i);
- System.out.println(object.getString("字段名1"));
- }