如何在android中检查元素是json对象还是json数组?

时间:2013-01-21 13:36:42

标签: android json

我想访问AmenityCodes你可以在图像中看到0位置Amenity Codes是Array但是49 positiin是json对象所以如何chek这是对象或json数组 enter image description here

enter image description here

  

MyActivity.java

for(int r=0;r<results.length();r++)
{

    HashMap<String, String>  map = new HashMap<String, String>();
    hotelrating=results.getJSONObject(r).get(TAG_STARRATING).toString();
    deeplink=results.getJSONObject(r).get(TAG_HOTELDEEPLINK).toString();

    JSONArray amenityarray=results.getJSONObject(r).getJSONArray(TAG_AMENITYCODES);

    Log.e("Amenitiescode","-->"+amenityarray);

}

1 个答案:

答案 0 :(得分:1)

替换:

JSONArray amenityarray=results.getJSONArray(r); 

使用:

JSONArray amenityarray=results.getJSONObject(r).getJSONArray("AmenityCodes");