通过JsonArray中的对象的某个属性获取JSONObject

时间:2017-11-06 10:18:02

标签: android retrofit2

我有resevationTickets json数组,我需要从上面提到的json数组获取特定的预订票证对象并使用票证id.how吗?

像这样的json数组:

reservation_tickets[
{object 1},{object 2},{object 3}
]

**对象有tx_id;

我需要使用tx_id

找到正确的票证

1 个答案:

答案 0 :(得分:0)

org.json.JSONObject
org.json.JSONArray

JSONArray jsonArray = new JSONArray(json_array);
int size = jsonArray.length();

for (int index = 0; index < size; index++) {
    JSONObject json = jsonArray.getJSONObject(index);
    if(json.getString("tx_id") == tx_id){
      //here we go...
    }
}
相关问题