问题描述
请问这种格式的json 数据该怎么解析? 小弟不才。只会解析简单的 {"A":"A","B":"B"} 这种类型的 { "result": { "rcResponse": {"List1":["1111","2222","3333"], "List2":["1111","2222","3333"], "spotList":["1111","2222","3333"], "version":"1.1", "transID":"001112300004560000", "flag":"1" }, "resultCode":"0"}}谢谢高手指导
解决方案
String jsonString = { "result":{"rcResponse": {"List1":["1111","2222","3333"],"List2":["1111","2222","3333"], "spotList":["1111","2222","3333"], "version":"1.1", "transID":"001112300004560000", "flag":"1" }, "resultCode":"0"} }; JSONObject jsonObj = JSONObject.fromObject(jsonString); JSONObject result = jsonObj.getJSONObject("result"); JSONObject rcResponse = result.getJSONObject("rcResponse"); JSONArray list1=jsonObj.getJSONArray("List1");JSONArray list2=jsonObj.getJSONArray("List2");System.out.println("list1[0]:"+list1.get(0)); JSONObject version= result.getJSONObject("version"); System.out.println("obj:"+obj.get("firstName")); 应该是[ 开头的 就用getJSONArray,普通的{开头就getJSONObject