Android reads json data (traversing jsonarray and jsonboject)-FenGKun, jsonjsonarray
Android reads json data (traversing jsonarray and jsonboject)
Public String getJson () {String jsonString = "{\" FLAG \ ": \" flag \ ", \" MESSAGE \ ": \" SUCCESS \", \ "name \": [{\ "name \": \ "jack \" },{ \ "name \": \ "lucy \"}]} "; // json string try {JSONObject result = new JSONObject (jsonstring); // convert to JSONObject int num = result. length (); JSONArray nameList = result. getJSONArray ("name"); // get JSONArray int length = nameList. length (); String aa = ""; for (int I = 0; I <length; I ++) {// traverse JSONAr Ray Log. d ("debugTest", Integer. toString (I); JSONObject oj = nameList. getJSONObject (I); aa = aa + oj. getString ("name") + "|";} Iterator <?> It = result. keys (); String aa2 = ""; String bb2 = null; while (it. hasNext () {// traverse JSONObject bb2 = (String) it. next (). toString (); aa2 = aa2 + result. getString (bb2) ;}return aa;} catch (JSONException e) {throw new RuntimeException (e );}}