【发布时间】:2012-10-07 13:42:15
【问题描述】:
使用
var arrayOfObjects = eval(photo.likes.data);
var objects = arrayOfObjects;
console.log(objects);
我得到下面的代码是 console.log 的回声
json
[
Object
full_name: "marcab12"
id: "181407552"
profile_picture: "http://images.instagram.com/profiles/profile_181407550_75sq_1339521398.jpg"
username: "marcab12"
__proto__: Object
,
Object
full_name: "Ramage1992"
id: "21574723"
profile_picture: "http://images.instagram.com/profiles/profile_21574703_75sq_1349343851.jpg"
username: "ramage_1992"
__proto__: Object
]
我怎样才能设法只在两行上显示用户名,因为我使用的 javascipt 似乎回显了 2 个对象。
编辑
$.each(likesperimage,function(index){
liked = likesperimage[index].username;
console.log(photo.id+' - '+liked);
});
【问题讨论】:
-
不要使用
eval:使用JSON.parse。 -
@lonesomeday JSON.parse 在旧版 IE 中不可用。
-
@Shusl - 对于较旧的浏览器,最好包含 github.com/douglascrockford/JSON-js 提供的 json2.js - 它具有
JSON.parse()和JSON.stringify()函数的实现跨度>
标签: javascript json instagram