打印数组
To print an array?
请帮助引导到json数组的标题我的尝试:
(function (jQuery){
var json = {
"news": [{
"img": "http://static3.www.net/img/300x300/2257740.jpeg",
"title": "qwerty1",
"url": "http://news.net.www.ru/newdata/adclick?ad=674134&bl=80802&ct=adpreview&st=16&in=YK2NFgCJu2FWSQoAjkkKAIhJCgBhSQoAfkkKAGJJCgA%3D&ag=19",
"id": "674134"
}, {
"img": "http://static5.www.net/img/300x300/2257778.jpeg",
"title": "qwerty2",
"url": "http://news.net.www.ru/newdata/adclick?ad=674190&bl=80802&ct=adpreview&st=16&in=YK2NFgCJu2FWSQoAjkkKAIhJCgBhSQoAfkkKAGJJCgA%3D&ag=19",
"id": "674190"
}, {
"img": "http://static3.www.net/img/300x300/2257776.jpeg",
"title": "qwerty3",
"url": "http://news.net.www.ru/newdata/adclick?ad=674184&bl=80802&ct=adpreview&st=16&in=YK2NFgCJu2FWSQoAjkkKAIhJCgBhSQoAfkkKAGJJCgA%3D&ag=19",
"id": "674184"
}, {
"img": "http://static2.www.net/img/300x300/2257748.jpeg",
"title": "qwerty4",
"url": "http://news.net.www.ru/newdata/adclick?ad=674145&bl=80802&ct=adpreview&st=16&in=YK2NFgCJu2FWSQoAjkkKAIhJCgBhSQoAfkkKAGJJCgA%3D&ag=19",
"id": "674145"
}, {
"img": "http://static1.www.net/img/300x300/2257766.jpeg",
"title": "qwerty5",
"url": "http://news.net.www.ru/newdata/adclick?ad=674174&bl=80802&ct=adpreview&st=16&in=YK2NFgCJu2FWSQoAjkkKAIhJCgBhSQoAfkkKAGJJCgA%3D&ag=19",
"id": "674174"
}, {
"img": "http://static3.www.net/img/300x300/2257750.jpeg",
"title": "qwerty6",
"url": "http://news.net.www.ru/newdata/adclick?ad=674146&bl=80802&ct=adpreview&st=16&in=YK2NFgCJu2FWSQoAjkkKAIhJCgBhSQoAfkkKAGJJCgA%3D&ag=19",
"id": "674146"
}]
}
//console.log(JSON.parse(json));
jQuery.each(JSON.parse(json), function(idx, obj) {
alert(idx + '__' + obj.news.title);
});
})($);
因此,控制台显示以下错误消息:
未捕获的SyntaxError:意外的令牌
您可以看到代码jsfiddle 的在线版本
将最后一位更改为-
jQuery.each(json.news, function(idx, obj) {
alert(idx + '__' + obj['title']);
});
})($);
您必须迭代json 的新闻
它已经被解析。因此JSON.parse
将抛出一个错误。修复是JSON.parse(json)
应该是简单的json
。
希望这能有所帮助。
相关文章:
- 如何用javascript打印php数组
- 试图打印/调用/或提醒数组中的对象:Getting Undefined
- 将数组的拼接分配给自身时,Javascript控制台打印不起作用
- 如何使用Jquery水平打印表中的数组元素,并在某个元素之后垂直打印
- React perf总是打印空数组
- 获取数组的长度-打印不正确的值
- 我的JS数组打印只显示结束值
- 使用显示/隐藏单选按钮将数组打印到 Div
- Chrome 开发工具显示将 jQuery 对象数组打印到屏幕上
- 将JavaScript数组打印为HTML,方括号和引号完好无损
- 将对象数组打印到HTML数据属性中
- 用JavaScript将数组打印到文本区域
- 我想只在 javascript 中使用数组打印 1 到 100 个数字
- AngularJS:把数组打印成字符串的好方法
- 如何使用数组打印偶数
- HTML5,如何匹配视频当前时间与标题数组打印标题在Javascript中
- 用JavaScript数组打印对象属性
- jQuery数组打印表
- 为什么这个javascript数组打印出0
- 在Java脚本中通过数组打印时出现错误