PHP不允许我访问解码的JSON

PHP不允许我访问解码的JSON,php,json,Php,Json,我使用API进行JSON调用,得到以下内容,这些内容似乎是正确格式化的JSON: { "pagination": {}, "meta": { "code": 200 }, "data": [ { "tags": [], "location": { "latitude": 37.42833, "name": "Stanfor

我使用API进行JSON调用,得到以下内容,这些内容似乎是正确格式化的JSON:

{
    "pagination": {},
    "meta": {
        "code": 200
    },
    "data": [
        {
            "tags": [],
            "location": {
                "latitude": 37.42833,
                "name": "Stanford University",
                "longitude": -122.1668,
                "id": 10138861
            },
            "comments": {
                "count": 0,
                "data": []
            },
            "filter": "Rise",
            "created_time": "1331327429",
            "link": "http://instagr.am/p/H91ykZpqUW/",
            "likes": {
                "count": 3,
                "data": [
                    {
                        "username": "razzles39",
                        "profile_picture": "http://images.instagram.com/profiles/profile_14316422_75sq_1322705511.jpg",
                        "id": "14316422",
                        "full_name": "razzles39"
                    },
                    {
                        "username": "mscaliti",
                        "profile_picture": "http://images.instagram.com/profiles/profile_10827166_75sq_1330704753.jpg",
                        "id": "10827166",
                        "full_name": "mscaliti"
                    },
                    {
                        "username": "mariecox",
                        "profile_picture": "http://images.instagram.com/profiles/profile_3987147_75sq_1324863102.jpg",
                        "id": "3987147",
                        "full_name": "Marie Cox"
                    }
                ]
            },
            "images": {
                "low_resolution": {
                    "url": "http://distilleryimage6.s3.amazonaws.com/4c6f97c46a2c11e180c9123138016265_6.jpg",
                    "width": 306,
                    "height": 306
                },
                "thumbnail": {
                    "url": "http://distilleryimage6.s3.amazonaws.com/4c6f97c46a2c11e180c9123138016265_5.jpg",
                    "width": 150,
                    "height": 150
                },
                "standard_resolution": {
                    "url": "http://distilleryimage6.s3.amazonaws.com/4c6f97c46a2c11e180c9123138016265_7.jpg",
                    "width": 612,
                    "height": 612
                }
            },
            "caption": {
                "created_time": "1331327500",
                "text": "Chillin with Brady at Stanford",
                "from": {
                    "username": "nicolelainefox",
                    "profile_picture": "http://images.instagram.com/profiles/anonymousUser.jpg",
                    "id": "17982472",
                    "full_name": "nicolelainefox"
                },
                "id": "143507936292283648"
            },
            "type": "image",
            "id": "143507334669706518_17982472",
            "user": {
                "username": "nicolelainefox",
                "website": "",
                "bio": "",
                "profile_picture": "http://images.instagram.com/profiles/anonymousUser.jpg",
                "full_name": "nicolelainefox",
                "id": "17982472"
            }
        }
    ]
}
然后在我的PHP脚本中使用
json\u decode
,使其成为我可以操作的东西,这是
var\u dump

object(stdClass)#1 (3) { ["pagination"]=> object(stdClass)#2 (0) { } ["meta"]=> object(stdClass)#3 (1) { ["code"]=> int(200) } ["data"]=> array(1) { [0]=> object(stdClass)#4 (12) { ["tags"]=> array(0) { } ["location"]=> object(stdClass)#5 (4) { ["latitude"]=> float(37.42833) ["name"]=> string(19) "Stanford University" ["longitude"]=> float(-122.1668) ["id"]=> int(10138861) } ["comments"]=> object(stdClass)#6 (2) { ["count"]=> int(0) ["data"]=> array(0) { } } ["filter"]=> string(4) "Rise" ["created_time"]=> string(10) "1331327429" ["link"]=> string(31) "http://instagr.am/p/H91ykZpqUW/" ["likes"]=> object(stdClass)#7 (2) { ["count"]=> int(3) ["data"]=> array(3) { [0]=> object(stdClass)#8 (4) { ["username"]=> string(9) "razzles39" ["profile_picture"]=> string(73) "http://images.instagram.com/profiles/profile_14316422_75sq_1322705511.jpg" ["id"]=> string(8) "14316422" ["full_name"]=> string(9) "razzles39" } [1]=> object(stdClass)#9 (4) { ["username"]=> string(8) "mscaliti" ["profile_picture"]=> string(73) "http://images.instagram.com/profiles/profile_10827166_75sq_1330704753.jpg" ["id"]=> string(8) "10827166" ["full_name"]=> string(8) "mscaliti" } [2]=> object(stdClass)#10 (4) { ["username"]=> string(8) "mariecox" ["profile_picture"]=> string(72) "http://images.instagram.com/profiles/profile_3987147_75sq_1324863102.jpg" ["id"]=> string(7) "3987147" ["full_name"]=> string(9) "Marie Cox" } } } ["images"]=> object(stdClass)#11 (3) { ["low_resolution"]=> object(stdClass)#12 (3) { ["url"]=> string(79) "http://distilleryimage6.s3.amazonaws.com/4c6f97c46a2c11e180c9123138016265_6.jpg" ["width"]=> int(306) ["height"]=> int(306) } ["thumbnail"]=> object(stdClass)#13 (3) { ["url"]=> string(79) "http://distilleryimage6.s3.amazonaws.com/4c6f97c46a2c11e180c9123138016265_5.jpg" ["width"]=> int(150) ["height"]=> int(150) } ["standard_resolution"]=> object(stdClass)#14 (3) { ["url"]=> string(79) "http://distilleryimage6.s3.amazonaws.com/4c6f97c46a2c11e180c9123138016265_7.jpg" ["width"]=> int(612) ["height"]=> int(612) } } ["caption"]=> object(stdClass)#15 (4) { ["created_time"]=> string(10) "1331327500" ["text"]=> string(30) "Chillin with Brady at Stanford" ["from"]=> object(stdClass)#16 (4) { ["username"]=> string(14) "nicolelainefox" ["profile_picture"]=> string(54) "http://images.instagram.com/profiles/anonymousUser.jpg" ["id"]=> string(8) "17982472" ["full_name"]=> string(14) "nicolelainefox" } ["id"]=> string(18) "143507936292283648" } ["type"]=> string(5) "image" ["id"]=> string(27) "143507334669706518_17982472" ["user"]=> object(stdClass)#17 (6) { ["username"]=> string(14) "nicolelainefox" ["website"]=> string(0) "" ["bio"]=> string(0) "" ["profile_picture"]=> string(54) "http://images.instagram.com/profiles/anonymousUser.jpg" ["full_name"]=> string(14) "nicolelainefox" ["id"]=> string(8) "17982472" } } } }
但是,当我使用echo($instagram_data[“data”])一切崩溃。如何访问此关联数组中的“数据”数组?以下是全部代码:

$instagram_handler = fopen("https://api.instagram.com/v1/locations/10138861/media/recent/?client_id=MY_ID", "r");
$instagram_json = stream_get_contents($instagram_handler);
fclose($instagram_handler);                                                                                                                                                      
$instagram_data = json_decode($instagram_json);                                                                                                                                                 
echo($instagram_data["data"]); //Breaks page

JSON被读取为对象,而不是关联数组。像这样加载它,您会很好:

$instagram\u data=json\u decode($instagram\u json,TRUE)

或者,像当前一样加载它,运行:


echo$instagram\u data->data
注意函数的
assoc
参数。如果省略它,decode将JSON视为对象而不是数组。因此,您应该能够通过以下方式访问它:

$instagram_data->data;
另一个选项是解码为数组,如下所示:

$instagram_data = json_decode($instagram_json, TRUE);

那么,有人对否决权发表评论吗?我错过了什么吗?:)可能重复的