如何访问JSON数组的内部元素。我的Json对象如下:
"numRecommenders": 0,
"publicProfileUrl": "http://www.linkedin.com/pub/heena-vyas/16/786/826",
"positions": {
"total": 1,
"positionList": [
{
"id": "91286566",
"title": "senior executive",
"company": {
"name": "Reliance",
"industry": "Oil & Energy",
"type": "Public Company",
"size": "10,001+ employees"
},
"isCurrent": true
}
]
},
我想访问positions.positionList.company.name
。
我的要求是运行GroupCommand
,如下所示:
GroupCommand cmd = new GroupCommand(collection,
null,
new BasicDBObject("positions.positionList.company.name", "Reliance"),
new BasicDBObject("count", 0),
"function(obj,prev) {prev.count++;}",
null);
使用上面的代码访问'name'不起作用。有人可以给我一个答案吗?
答案 0 :(得分:0)
var name = jsonObject.positions.positionlist[0].company.name;
请注意,您的positionlist
是一个长度为jsonObject.positions.total
的数组。