1、json与jsonp的区别(待查)
2、要遍历的数据如下:
{"status": "ok", "code": 200, "data": {"343946": {"8144": {"feed": 0, "instagram": 0, "livefyre": 21, "facebook": 0, "total": 21, "twitter": 0}}, "343945": {"2649": {"feed": 0, "instagram": 0, "livefyre": 42, "facebook": 0, "total": 42, "twitter": 0}}}}
3、数据来源:
https://coxnews.bootstrap.fyre.co/api/v1.1/public/comments/ncomments/MzQzOTQ1OjI2NDl8MzQzOTQ2OjgxNDQ==.json
4、代码如下:
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
//$.each( [4,1,2], function(i, n){
// alert( "Item #" + i + ": " + n );
//});
//$.each( { name: "John", lang: "JS" }, function(i, n){
// alert( "Name: " + i + ", Value: " + n );
//});
$.ajax({
dataType: 'jsonp',
url: 'https://coxnews.bootstrap.fyre.co/api/v1.1/public/comments/ncomments/MzQzOTQ1OjI2NDl8MzQzOTQ2OjgxNDQ==.json',
success: function(data) {
var dataObj = eval(data).data;
//一层循环
$.each(dataObj, function(n1, value) {
alert(n1);
//二层循环
$.each(value,function(n2,value1){
alert(n2);
//三层循环
$.each(value1,function(n3,value2){
alert(n3);
alert(value2);
});
});
//for (var i = 0; i < value.length; i++) {
// alert(value[i]);
// }
});
}
});
}
);
</script>
</head>
<body>
<div>TODO write content</div>
</body>
</html>
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦