我有一个关于如何解析json文件的问题。我的json结构是这样的:获取json数组值android
{
"contacts": [
{
"id": "c200",
"name": "Ravi Tamada",
"email": "[email protected]",
"address": "xx-xx-xxxx,x - street, x - country",
"gender" : "male",
"services": [
"laundry",
"wifi",
"tv",
"swimming pool",
"bar"
],
"phone": [
910000000000,
00000000,
000000
]
},
{
"id": "c201",
"name": "Johnny Depp",
"email": "[email protected]",
"address": "xx-xx-xxxx,x - street, x - country",
"gender" : "male",
"services": [
"laundry",
"wifi",
"tv",
"swimming pool",
"bar"
],
"phone": [
0000000000,
00000000,
00000000
]
}
]
如何获取电话值和服务值?
phones = jsonObj.getJSONArray(TAG_PHONE);
for (int x = 0; x < phones.length(); x++) {
}
因为拿到例如ID我haven't有问题:
for (int i = 0; i < contacts.length(); i++) {
JSONObject c = contacts.getJSONObject(i);
String id = c.getString(TAG_ID);
// tmp hashmap for single contact
HashMap<String, String> contact = new HashMap<String, String>();
// adding each child node to HashMap key => value
contact.put(TAG_ID, id);
contactList.add(contact);
非常感谢您
复制到检索相应的对象和环接触前请交 http://stackoverflow.com/questions/19197015/android-parse-json-array检查字符串 – 2014-09-30 13:19:17
参考这[链接](http://stackoverflow.com/questions/14708935/how-to-get-json-array-values-in-android) – Yugesh 2014-09-30 13:22:30