欢迎来到-个人主页,希望本页面可以帮到您,您也可以给我在线留言,反馈建议,我愿意倾听您的声音... 留言

jQuery 遍历输出数组

2019-06-14 14:0

声明数组是,并输出

var json = [

{"id":"1","tagName":"apple"},

{"id":"2","tagName":"orange"},

{"id":"3","tagName":"banana"},

{"id":"4","tagName":"watermelon"},

{"id":"5","tagName":"pineapple"}

];

 

$.each(json, function(idx, obj) {

alert(obj.tagName);

});



声明字符,将字符变成数组,遍历输出

var json = '[{"id":"1","tagName":"apple"},{"id":"2","tagName":"orange"},

{"id":"3","tagName":"banana"},{"id":"4","tagName":"watermelon"},
{"id":"5","tagName":"pineapple"}]';
 
$.each(JSON.parse(json), function(idx, obj) {
alert(obj.tagName);
});
 
//or 
 
$.each($.parseJSON(json), function(idx, obj) {
alert(obj.tagName);
});