假设你的JSON字符串在可变$json
,它是这样的:
var employees_list = JSON.parse($json);
然后,您可以通过访问信息:
employees_list[0].employees.education // gives you "BE\/B.Tech"
// and
employees_list[0]["0"].count // gives you 1.
您还可以循环数组和访问过所有不同的education
这种方式。
更新:
为了更好地展现其表达访问哪些信息:
[ // employees_list
{ // employees_list[0]
"employees": { // employees_list[0].employees
"education": "BE\/B.Tech" // employees_list[0].employees.education
},
"0": { // employees_list[0]["0"]
"count": "1" // employees_list[0]["0"].count
}
},
{ // employees_list[1]
"employees": { // employees_list[1].employees
"education": "MBA" // employees_list[1].employees.education
},
"0": { // employees_list[1]["0"]
"count": "3" // employees_list[1]["0"].count
}
}
]
一般employees_list[0].employees
相同employees_list[0]["employees"]
但这并不对数字工作,因为属性和变量是不允许以数字开头。所以你可以只使用使用employees_list[0].["0"]
而不是employees_list[0].0
。
虽然你的JSON字符串的结构看起来有点奇怪。如果可以的话,你应该考虑采用不同的结构。
例如:
[
{
"education": "BE\/B.Tech",
"count": "1"
},
{
"education": "MBA"
"count": "3"
}
]
在原来的JSON字符串的"0"
关键似乎起不到任何作用,只是在接入复杂。
您可以粘贴您尝试使用的代码来检索此JSON输出吗? – BoltClock 2010-07-18 19:07:27