[英]Parsing json (2 arrays) in Android
我需要解析具有两个数组的JSON。
分别为: {"attending": [], "people": []}
我试过了
JSONObject AttendingArray = new JSONObject(resp);
JSONArray ParkArray = new JSONArray("people");
JSONArray AttendingArray = new JSONArray("attending");
但这不起作用
12-01 22:47:53.074: WARN/System.err(30814): org.json.JSONException: Value people of type java.lang.String cannot be converted to JSONArray
谢谢!
JSONObject obj = new JSONObject(resp);
JSONArray ParkArray = new JSONArray(obj.getString("people"));
JSONArray AttendingArray = new JSONArray(obj.getString("attending"));
您必须将实际的JSON传递给JSONArray
构造函数,而不仅仅是json数组的名称- new JSONArray
构造函数调用不知道响应,因此您需要给它一些数据,而不仅仅是“人”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.