【问题标题】:how to parse jsonobjects with same name inside jsonarray in android? [duplicate]如何在android的jsonarray中解析同名的jsonobjects? [复制]
【发布时间】:2017-08-15 20:42:33
【问题描述】:
{
    "terms": [{
        "offset": 0,
        "value": "Nerkundram"
    }, {
        "offset": 12,
        "value": "Chennai"
    }, {
        "offset": 21,
        "value": "Tamil Nadu"
    }, {
        "offset": 33,
        "value": "India"
    }]
}

【问题讨论】:

标签: android arrays json


【解决方案1】:

使用这个:

try{
JSONObject json = new JSONObject(jsonString);
JSONArray jsonArray = json.getJSONArray("terms");
for(int i=0;i<jsonArray.length();i++){
     JSONObject object = jsonArray.getJSONObject(i);
     String offset = object.getString("offset");
     String value = object.getString("value");
     //rest of the strings..
    }
 }
 catch (JSONException e){
       e.printStackTrace();
}

【讨论】:

  • 感谢您的回答@rafsanahmad007
  • 如果答案有助于通过单击答案左侧的勾号将其标记为正确...thankx.@Chandana_Raj
猜你喜欢
  • 2012-06-21
  • 1970-01-01
  • 2018-10-16
  • 1970-01-01
  • 2013-06-12
  • 2012-10-05
  • 1970-01-01
  • 1970-01-01
  • 2017-05-01
相关资源
最近更新 更多