douhao123457 2013-04-23 02:19
浏览 79
已采纳

json_decode无法显示数组[关闭]

OK I have looked at a few examples and I can't seem to display the array or an element. It keeps coming back as null-. I have the following JSON (from 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: [

        ]
    }
})

I have attempted to add it to an array like so

$array =json_decode($data, true);

However no matter how I try to print or check the contents it all comes back as null I really am just trying to print out the lat lng and adminArea5. Any help would be great.

Here is the full code

<?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条回答 默认 最新

  • dongxu8533486 2013-04-23 02:44
    关注

    Don't include the 'callback' => 'ResultSet' parameter, that makes the response a JSONP response.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?