-3

好的,我查看了一些示例,但似乎无法显示数组或元素。它一直以 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);

但是,无论我如何尝试打印或检查内容,它都返回为空,我真的只是想打印出 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();
}
?>
4

1 回答 1

1

不要包含'callback' => 'ResultSet'使响应成为JSONP响应的参数。

于 2013-04-23T02:44:50.400 回答