Home  >  Article  >  Backend Development  >  ajax get请求得到了一个json格式的数据,在js中如何遍历出来

ajax get请求得到了一个json格式的数据,在js中如何遍历出来

WBOY
WBOYOriginal
2016-06-13 12:09:161333browse

ajax get请求得到了一个json格式的数据,在js中怎么遍历出来
nbsp;html>



    
    







------解决思路----------------------



------解决思路----------------------
//data为json格式  返回数据位: {"name":"liweitao","age":"23"}
$.get("/world",function(data,status){
//在js中我怎么得到name的值,怎么遍历
var d = eval('(' + data + ')');
alert(d.name);
});
 
$.get("/world",function(data,status){
//在js中我怎么得到name的值,怎么遍历
alert(data.name);
}, 'json'); //如果加上这个属性

------解决思路----------------------
for in 循环或者直接for循环,但是如果直接for循环的话你就得使用$.ajax来重新调整你的代码了。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn