Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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
如何使用jquery从嵌套的JSON对象获取值?_Jquery_Json - Fatal编程技术网

如何使用jquery从嵌套的JSON对象获取值?

如何使用jquery从嵌套的JSON对象获取值?,jquery,json,Jquery,Json,我试图通过调用JSON对象来使用jquery创建ajax搜索。目前,我能够从如下格式的对象中迭代结果: [{ "ID": "4207b2d5b8994bd8a19c28815c07663d", "position": 1, "voteUpCount": 16, "voteDownCount": 32, "categories": [{ "position": 1, "category": "7d435c8a70f7447ea

我试图通过调用JSON对象来使用jquery创建ajax搜索。目前,我能够从如下格式的对象中迭代结果:

[{
    "ID": "4207b2d5b8994bd8a19c28815c07663d",
    "position": 1,
    "voteUpCount": 16,
    "voteDownCount": 32,
    "categories": [{
        "position": 1,
        "category": "7d435c8a70f7447ea03d4cbba11f4686"
    }],
    "keywords": [
        "key-word"
    ],
    "title": "This is a title",
    "body": "<p>this is description</p>",
    "outdated": false,
    "slug": "this-is-an-article",
    "views": 0,
    "labelName": [
        ""
    ],
    "locale": "gb",
    "storeName": "mystore",
    "id": 4207
},{
    "ID": "4207b2d5b8994bd8a19c28815c07663d",
    "position": 1,
    "voteUpCount": 16,
    "voteDownCount": 32,
    "categories": [{
        "position": 1,
        "category": "7d435c8a70f7447ea03d4cbba11f4686"
    }],
    "keywords": [
        "key-word"
    ],
    "title": "This is a title",
    "body": "<p>this is description</p>",
    "outdated": false,
    "slug": "this-is-an-article",
    "views": 0,
    "labelName": [
        ""
    ],
    "locale": "gb",
    "storeName": "mystore",
    "id": 4207
} ]

任何帮助都将不胜感激。

所有数据都包含响应变量“data.response”

$.each(data.response, function(key, value){
        article_data += '<div class="faq-item" data-artcile><a href="#">'+ value.title +'</a><i class="fa fa-chevron-down"></i></div>'; 
        article_data += '<div class="faq-answer">'+ value.body +'</div>';
});
$。每个(数据、响应、函数(键、值){
第九条数据+='';
article_data+=''+value.body+'';
});

结构是相同的,数组现在就在
response
属性中,所以将它添加到:
$。每个(data.response,function(){…
@rorymcrossan,谢谢这正是正确的解决方案。它现在工作起来很有魅力。
    {
    "response": [{
    "ID": "4207b2d5b8994bd8a19c28815c07663d",
    "position": 1,
    "voteUpCount": 16,
    "voteDownCount": 32,
    "categories": [{
        "position": 1,
        "category": "7d435c8a70f7447ea03d4cbba11f4686"
    }],
    "keywords": [
        "key-word"
    ],
    "title": "This is a title",
    "body": "<p>this is description</p>",
    "outdated": false,
    "slug": "this-is-an-article",
    "views": 0,
    "labelName": [
        ""
    ],
    "locale": "gb",
    "storeName": "mystore",
    "id": 4207
},{
    "ID": "4207b2d5b8994bd8a19c28815c07663d",
    "position": 1,
    "voteUpCount": 16,
    "voteDownCount": 32,
    "categories": [{
        "position": 1,
        "category": "7d435c8a70f7447ea03d4cbba11f4686"
    }],
    "keywords": [
        "key-word"
    ],
    "title": "This is a title",
    "body": "<p>this is description</p>",
    "outdated": false,
    "slug": "this-is-an-article",
    "views": 0,
    "labelName": [
        ""
    ],
    "locale": "gb",
    "storeName": "mystore",
    "id": 4207
} ],
    "http_code": 200
}
value.response.title
$.each(data.response, function(key, value){
        article_data += '<div class="faq-item" data-artcile><a href="#">'+ value.title +'</a><i class="fa fa-chevron-down"></i></div>'; 
        article_data += '<div class="faq-answer">'+ value.body +'</div>';
});