gpt4 book ai didi

jquery - 如何在jquery中解析json对象数组

转载 作者:行者123 更新时间:2023-12-03 23:01:19 25 4
gpt4 key购买 nike

我有以下 json 对象数组

[{"id":10,"name":"sinu"},{"id":20,"name":"shinto"}]

我如何使用 jquery 解析它并获取每个名称和 ID。

提前致谢

最佳答案

var data = [{"id":10,"name":"sinu"},{"id":20,"name":"shinto"}];
jQuery(data).each(function(i, item){
$('#output').append(item.id + ' ' + item.name + '<br>');
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="output"></div>

var data = [{"id":10,"name":"sinu"},{"id":20,"name":"shinto"}];
jQuery(data).each(function(i, item){
console.log(item.id, item.name)
})

关于jquery - 如何在jquery中解析json对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30115437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com