【发布时间】:2014-11-25 03:23:32
【问题描述】:
我有一个关于如何解析 json 文件的问题。我的json结构是这样的:
{
"contacts": [
{
"id": "c200",
"name": "Ravi Tamada",
"email": "ravi@gmail.com",
"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": "johnny_depp@gmail.com",
"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 我没有遇到问题:
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);
非常感谢
【问题讨论】:
-
参考这个Link