繁体   English   中英

如何遍历此JSON?

[英]How do I iterate through this 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。

抱歉,我是新来的...。

您可以使用:

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 < jsonObj.SentenceFacts.length; i++) {
    for (var key in jsonObj.SentenceFacts[i]) {
        jsonObj.SentenceFacts[i].hasOwnProperty(key) && console.log(key, jsonObj.SentenceFacts[i][key]);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM