The relationship between JSONObject and JSONArray.
The top layer of the JSON string must be a JSONObject. the next layer of JSONObject can contain JSONArray and JSONArray contains several jsonobjects. Example:
Package myJson; import net. sf. json. JSONArray; import net. sf. json. JSONObject; public class myJson {static String jsonString = new String ("{'data': [{'id': 1, 'studentid': '000000', 'name ': 'zhang san'}, "+" {'id': 2, 'studentid': '000000', 'name': 'lily'}, "+" {'id ': 3, 'studentid': '20170101', 'name': 'wangwu'}]} "); public static void main (String args []) {JSONObject jsonObject = JSONObject. fromObject (jsonString); JSONArray jsonArray = jsonObject. getJSONArray ("Data"); JSONObject jsonObject2; for (int I = 0; I <jsonArray. size (); I ++) {jsonObject2 = (JSONObject) jsonArray. get (I); System. out. println (String. valueOf (I) + ":" + jsonObject2.toString ());}}}
The above code first obtains a JSONObject, then obtains the "Data" JSONArray based on this JSONObject, and then obtains three jsonobjects from JSONArray. The running result is as follows: