Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.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
Javascript 如何迭代这个JSON?_Javascript_Jquery_Json - Fatal编程技术网

Javascript 如何迭代这个JSON?

Javascript 如何迭代这个JSON?,javascript,jquery,json,Javascript,Jquery,Json,我有一个json格式: { "SentenceFacts": [ { "Objective : ": "none" }, { " Seeking a challenging position where my analytical and problem solving skills can be put in for the successful execution of the organiz

我有一个json格式:

{
      "SentenceFacts": [
        {
          "Objective : ": "none"
        },
        {
          " Seeking a challenging position where my analytical and problem solving skills can be put in for the successful execution of the organizations projects .": "none"
        },
        {
          "Summary : ": "none"
    } ]
}
如何使用jQuery/JS获取其中的每个名称-值对

我需要在
[]

我在
$.each()
函数中看到过建议的解决方案,但这似乎只适用于格式为
{name:value}
的JSON

对不起,我是新手……

您可以使用:

for(var i=0; i<json.SentenceFacts.length; i++) {
  var item = json.SentenceFacts[i];
  for(var prop in item) {
     // prop here is "Objective", " Seeking a challenging position ..." etc 
     console.log("key: "  , prop);     
     console.log("value: ", item[prop]);
  }
}: 
for(var i=0;i
for(var i=0;i
这不是一个有效的JSON这是你在那里得到的一些蹩脚格式的JSON,这是来自你的服务器还是第三方的?Jsonlint是一个很好的工具,可以检查你的JSON是否有效@JonKoops我确信换行符是一个输入错误,请删除它,它是一个有效的object@Robert可能吧,但我倾向于不做假设。尤其是在堆栈溢出方面;)
for (var i = 0; i < jsonObj.SentenceFacts.length; i++) {
    for (var key in jsonObj.SentenceFacts[i]) {
        jsonObj.SentenceFacts[i].hasOwnProperty(key) && console.log(key, jsonObj.SentenceFacts[i][key]);
    }
}