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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?