0

如果我有下面的代码,我将如何显示喜欢下的用户名?目前我用来photo.images.low_resolution.url向我展示低分辨率图像的urk,但我无法弄清楚喜欢部分。

{
    "data": [{
        "location": {
            "id": "833",
            "latitude": 37.77956816727314,
            "longitude": -122.41387367248539,
            "name": "Civic Center BART"
        },
        "comments": {
            "count": 16,
            "data": [ ... ]
        },
        "caption": null,
        "link": "http://instagr.am/p/BXsFz/",
        "likes": {
            "count": 190,
            "data": [{
                "username": "shayne",
                "full_name": "Shayne Sweeney",
                "id": "20",
                "profile_picture": "..."
            }, {...subset of likers...}]
        },
        "created_time": "1296748524",
        "images": {
            "low_resolution": {
                "url": "http://distillery.s3.amazonaws.com/media/2011/02/03/efc502667a554329b52d9a6bab35b24a_6.jpg",
                "width": 306,
                "height": 306
            },
            "thumbnail": {
                "url": "http://distillery.s3.amazonaws.com/media/2011/02/03/efc502667a554329b52d9a6bab35b24a_5.jpg",
                "width": 150,
                "height": 150
            },
            "standard_resolution": {
                "url": "http://distillery.s3.amazonaws.com/media/2011/02/03/efc502667a554329b52d9a6bab35b24a_7.jpg",
                "width": 612,
                "height": 612
            }
        },
        "type": "image",
        "filter": "Earlybird",
        "tags": [],
        "id": "22987123",
        "user": {
            "username": "kevin",
            "full_name": "Kevin S",
            "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_3_75sq_1295574122.jpg",
            "id": "3"
        }
    },
    ...]
}
4

2 回答 2

1

看到这个jsFiddle。注意第二个条目没有数据。

于 2012-10-06T23:40:49.203 回答
0

请:

            //photo = your object
            //Make sure to remove empty objects({...}) as in your code example.

            for (var i = 0; i < photo.data.length; i++) {
                    var photoData = photo.data[i];
                    for (var x = 0; x < photoData.likes.data.length; x++) {
                        //Do what ever you want with the like's user...
                        var likeData = photoData.likes.data[x];
                        alert(likeData.username);
                    }
                }

下次console.log用于浏览您的对象: 在此处输入图像描述

于 2012-10-06T23:43:08.223 回答