jQuery 遍历json数组的实现代码

<script type="text/javascript"> 
var d1 =[{"text":"王家湾","value":"9"},{"text":"李家湾","value":"10"},{"text":"邵家湾","value":"13"}];
$(d1).each(function(){ 
alert(this.text+" "+this.value); 
}); 
</script> 

不用JQuery 

<script type="text/javascript"> 
var json = {"options":"[{\"text\":\"王家湾\",\"value\":\"9\"},{\"text\":\"李家湾\",\"value\":\"10\"},{\"text\":\"邵家湾\",\"value\":\"13\"}]"} 
json = eval(json.options) 
for(var i=0; i<json.length; i++) 
{ 
alert(json[i].text+" " + json[i].value) 
} 
</script> 

 

posted @ 2016-07-26 18:16  汪强胜  Views(295)  Comments(0Edit  收藏  举报