我有一個關於如何解析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