0

我有一个 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()功能的解决方案,但这似乎仅适用于 JSON 格式{name:value}

对不起,我是新手……

4

2 回答 2

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]);
  }
}: 
于 2013-11-08T11:49:21.970 回答
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]);
    }
}
于 2013-11-08T11:50:42.867 回答