Arrays 访问JSON数组的内部元素
如何访问JSON数组的内部元素。我的Json对象如下所示:Arrays 访问JSON数组的内部元素,arrays,json,element,Arrays,Json,Element,如何访问JSON数组的内部元素。我的Json对象如下所示: "numRecommenders": 0, "publicProfileUrl": "http://www.linkedin.com/pub/heena-vyas/16/786/826", "positions": { "total": 1, "positionList": [ { "id": "91286566",
"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
}
]
},
GroupCommand cmd = new GroupCommand(collection,
null,
new BasicDBObject("positions.positionList.company.name", "Reliance"),
new BasicDBObject("count", 0),
"function(obj,prev) {prev.count++;}",
null);
我想访问positions.positionList.company.name
。
我的要求是运行GroupCommand
,如下所示:
"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
}
]
},
GroupCommand cmd = new GroupCommand(collection,
null,
new BasicDBObject("positions.positionList.company.name", "Reliance"),
new BasicDBObject("count", 0),
"function(obj,prev) {prev.count++;}",
null);
使用上述代码访问“名称”无效。有人能给我一个答案吗
var name = jsonObject.positions.positionlist[0].company.name;
请注意,您的positionlist
是长度jsonObject.positions.total
的数组
请注意,您的positionlist
是长度jsonObject.positions.total
的数组