小编典典

如何迭代 JSON 结构?

all

社区在5 个月前审查了是否重新打开此问题并将其关闭:

原始关闭原因未解决

我有以下 JSON 结构:

[{ "id":"10", "class": "child-of-9" }, { "id": "11", "classd": "child-of-10" }]

如何使用 JavaScript 对其进行迭代?


阅读 83

收藏
2022-03-07

共1个答案

小编典典

取自jQuery 文档

var arr = [ "one", "two", "three", "four", "five" ];
var obj = { one:1, two:2, three:3, four:4, five:5 };

jQuery.each(arr, function() {
  $("#" + this).text("My id is " + this + ".");
  return (this != "four"); // will stop running to skip "five"
});

jQuery.each(obj, function(i, val) {
  $("#" + i).append(document.createTextNode(" - " + val));
});
2022-03-07