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似乎回显了两个对象。
编辑
$.each(likesperimage,function(index){
liked = likesperimage[index].username;
console.log(photo.id+' - '+liked);
});
不要使用'eval':使用'JSON.parse'。 – lonesomeday
@lonesomeday JSON.parse在较旧的IE中不可用。 – Anoop
@Shusl - 对于较老的浏览器,最好包含可从https://github.com/douglascrockford/JSON-js获得的* json2.js *,它具有'JSON.parse()'和'JSON.stringify ()'函数 – techfoobar