Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 访问JSON数组的内部元素_Arrays_Json_Element - Fatal编程技术网

Arrays 访问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",

如何访问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
            }
        ]
    },
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
的数组