如何迭代这个JSON?

时间:2013-11-08 11:43:54

标签: 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 organizations projects .": "none"
        },
        {
          "Summary : ": "none"
    } ]
}

如何使用jQuery / JS获取每个名称值对?

我需要在[ ]

中获取名称值对

我见过$.each()函数的解决方案,但这似乎只适用于{name:value}形式的JSON。

对不起,我是新来的......

2 个答案:

答案 0 :(得分:1)

您可以使用:

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]);
  }
}: 

答案 1 :(得分:0)

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]);
    }
}