Android JSONObject中的JSONArray,如何检索?
我有一个JSONObject,其中包含两个JSONArray和JSONObject。我想知道如何访问JSONObject中的JSONArray中的JSONObject?(JSONeption!) 澄清(即使我对此感到困惑) 我首先得到一个JSONObject 此对象包含2个JSONArray 这两个数组有X和Y数量的JSONObject 我如何到达“最深”的JSONObject?如何“展开”第一个JSONObject以获得前2个JSONArray 有什么提示或技巧可以分享吗 有什么提示或技巧可以分享吗 是的,使用类似于Google的JSON库 这里是一个使用它的参考Android JSONObject中的JSONArray,如何检索?,android,json,arrays,Android,Json,Arrays,我有一个JSONObject,其中包含两个JSONArray和JSONObject。我想知道如何访问JSONObject中的JSONArray中的JSONObject?(JSONeption!) 澄清(即使我对此感到困惑) 我首先得到一个JSONObject 此对象包含2个JSONArray 这两个数组有X和Y数量的JSONObject 我如何到达“最深”的JSONObject?如何“展开”第一个JSONObject以获得前2个JSONArray 有什么提示或技巧可以分享吗 有什么提示或技巧可以
祝你好运 Yuo可以使用类似这样的东西
newjsonobject(json).getJSONArray(arrayname1).getJSONObject(positionx)
这里
json
是json响应字符串arrayname1
是第一个数组的名称。而poitionx
是x JSONObjects的任意位置。类似地,您可以使用
新JSONObject(json).getJSONArray(arrayname2).getJSONObject(positiony)
作为另一个对象。以下是示例。
假设我们有一个JSONObject“Space”,它有两个数组:1和2
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("url");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream instream = entity.getContent();
String result= convertStreamToString(instream);
JSONObject json=new JSONObject(result);
JSONObject resp= (JSONObject) json.get("response");
JSONObject Space=resp.getJSONObject("Space");
JSONArray One=Space.getJSONArray("one");
int Length=One.length();
for(int i=0;i<length;i++)
{
JSONObject item = (JSONObject) items.get(j);
String x=item.getString("x);
String y=item.getString("y");
System.out.println("x = "+x+" , y = "+y);
}
HttpClient-HttpClient=newdefaulthttpclient();
HttpPost HttpPost=新的HttpPost(“url”);
HttpResponse response=httpclient.execute(httppost);
HttpEntity=response.getEntity();
InputStream instream=entity.getContent();
字符串结果=convertStreamToString(流内);
JSONObject json=新的JSONObject(结果);
JSONObject resp=(JSONObject)json.get(“响应”);
JSONObject Space=resp.getJSONObject(“空间”);
JSONArray One=Space.getJSONArray(“One”);
int Length=1.Length();
对于(int i=0;我在这里找到了一个很好的例子