json_decode无法显示数组

时间:2013-04-23 02:19:19

标签: php arrays json

好的我看了几个例子,我似乎无法显示数组或元素。它一直回来为null-。我有以下JSON(来自mapquest)

renderGeocode({
    results: [
        {
            locations: [
                {
                    latLng: {
                        lng: -90.1978,
                        lat: 38.627201
                    },
                    adminArea4: "Saint Louis City",
                    adminArea5Type: "City",
                    adminArea4Type: "County",
                    adminArea5: "Saint Louis",
                    street: "",
                    adminArea1: "US",
                    adminArea3: "MO",
                    type: "s",
                    displayLatLng: {
                        lng: -90.1978,
                        lat: 38.627201
                    },
                    linkId: 0,
                    postalCode: "",
                    sideOfStreet: "N",
                    dragPoint: false,
                    adminArea1Type: "Country",
                    geocodeQuality: "CITY",
                    geocodeQualityCode: "A5XAX",
                    mapUrl: "http://www.mapquestapi.com/staticmap/v4/getmap?key=123456789&type=map&size=225,160&pois=purple-1,38.627201,-90.1978,0,0|&center=38.627201,-90.1978&zoom=12&rand=1390479880",
                    adminArea3Type: "State"
                }
            ],
            providedLocation: {
                location: "SAint Louis,mo"
            }
        }
    ],
    options: {
        ignoreLatLngInput: false,
        maxResults: -1,
        thumbMaps: true
    },
    info: {
        copyright: {
            text: "© 2013 MapQuest, Inc.",
            imageUrl: "http://api.mqcdn.com/res/mqlogo.gif",
            imageAltText: "© 2013 MapQuest, Inc."
        },
        statuscode: 0,
        messages: [

        ]
    }
})

我试图将它添加到像这样的数组

$array =json_decode($data, true);

然而无论我如何尝试打印或检查内容,它都会返回null我真的只是想打印出lat lng和adminArea5。 任何帮助都会很棒。

这是完整的代码

<?php
$where = filter_input(INPUT_GET, 'where', FILTER_SANITIZE_STRING);
$source = "getLat";
if ($source =="getLat")
{
    ob_start();
    $getsource = array('location' =>$where,
            'type'=>$getWhat,
            'callback'=>'ResultSet'
    );
    $url = "http://www.mapquestapi.com/geocoding/v1/address?key=123456789" . http_build_query($getsource, '', "&");
//print_r($url);
    $data_mapquest = file_get_contents($url);
    $array = json_decode($data_mapquest, true);
    ob_end_flush();
}
?>

1 个答案:

答案 0 :(得分:1)

请勿添加'callback' => 'ResultSet'参数,以使回复成为JSONP响应。