我有这样的数据json:
{"output":{"id":"1","nama":"one"}},
{"output":{"id":"2","nama":"two"}},
{"output":{"id":"3","nama":"three"}}
如何让数据json逐一返回。
示例结果如下:
循环1
{"output":{"id":"1","nama":"one"}}
循环2
{"output":{"id":"2","nama":"two"}}
循环3
{"output":{"id":"3","nama":"three"}}
谢谢,希望有人能回答:D
答案 0 :(得分:0)
您在寻找each loop
吗?
var data = [{"output":{"id":"1","nama":"one"}},
{"output":{"id":"2","nama":"two"}},
{"output":{"id":"3","nama":"three"}}];
$.each(data, function(i, item) {
console.log(item);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
答案 1 :(得分:0)
您可以使用jquery .each
循环,但需要使用[]
表示法将数据放入数组中:
var jsonData = [
{"output":{"id":"1","nama":"one"}},
{"output":{"id":"2","nama":"two"}},
{"output":{"id":"3","nama":"three"}}
];
$.each(jsonData , function(k, v) {
console.log ("key",k,"value", v);
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;