March 6, 2019
jQuery: 遍历json字符串, 遍历object数组,报错:Uncaught TypeError: Cannot use ‘in’ operator to search for ‘156’, Uncaught SyntaxError: Unexpected token k in JSON at position 2, loop over JSON string – $.each example

遍历一个json字符串,或者object数组的方法:
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);
});
Above code snippet is working fine, prompts the “app… Read More