我有json数组 var data = '[{ "name": "Violet", "occupation": "character" },{ "name": "orange", "occupation": "color" }]' 如何解析数据并使用prototype.js迭代它? 有一个名为evalJSON()的函数 var data = '[{ "name": "Viole
var data = '[{ "name": "Violet", "occupation": "character" },{ "name": "orange", "occupation": "color" }]'
如何解析数据并使用prototype.js迭代它?
有一个名为evalJSON()的函数var data = '[{ "name": "Violet", "occupation": "character" },{ "name": "orange", "occupation": "color" }]'; data = data.evalJSON(); //for more security: data = data.evalJSON(true); //sanitizes data before processing it
然后只需使用for迭代数组:
for (var i=0;i<data.length;i++) { //do whatever you like with data[i]; }
或者使用prototypeJS .each()函数:
data.each(function(el){ //do whatever you like with el });