解析在android中的jsonobject里面的Json数组

时间:2016-08-17 19:38:26

标签: android json parsing android-volley

[
  {
    "subject": "Top exotic beaches in Greece",
    "participants": [
      "Aristotle", "Socrates"
    ],
    "preview": "Plato,\nThis is what I was talking about for the bachelor party!",
    "isRead": false,
    "isStarred": true,
    "ts": 1471451322,
    "id": 5
  }
]

如何解析"参与者"从这个json ... thanx提前

2 个答案:

答案 0 :(得分:1)

try {
    JSONArray participants = jsonObject.getJSONArray("participants")
    for (int i = 0; i < participants.length(); i++) {
        yourArrayList.add(participants.getString(i))
    }
} catch(JSONException e) {
    // Handle exception.
}

答案 1 :(得分:1)

JSONArray jsonArray = new JSONArray(mainJSON.getJSONArray("participants"))

然后你就像这样使用你的对象:

 jsonArray.getJSONObject(0)