我是 android 和 JSON 解析的新手。在这里,我得到了我的 json 响应。现在我的 jsonarray 中有几个这样的响应。我想知道的是如何从这个响应中获取单个值。
即我怎样才能从这些响应中只获取“id”:
{"id":"c200","gender":"male","phone":{"office":"00 000000","home":"00 000000","mobile":"+91 0000000000"},"address":"xx-xx-xxxx,x - street, x - country","email":"ravi@gmail.com","name":"Ravi Tamada"}
{"id":"c201","gender":"male","phone":{"office":"00 000000","home":"00 000000","mobile":"+91 0000000000"},"address":"xx-xx-xxxx,x - street, x - country","email":"johnny_depp@gmail.com","name":"Johnny Depp"}
我只想要这两个响应的 id。
我的代码是
JSONObject jobject = jparse.getJSONFromUrl(url);
contacts = jobject.getJSONArray(TAG_CONTACTS);
for(int i = 0 ; i < contacts.length() ; i++)
{
JSONObject c = contacts.getJSONObject(i);
String id = c.getString(TAG_ID);
Log.i("TAG", "STRING VALUE:" + contacts.getString(i));
String name = c.getString(TAG_NAME);
String email = c.getString(TAG_EMAIL);
String address = c.getString(TAG_ADDRESS);
String gender = c.getString(TAG_GENDER);
}