Home >Backend Development >PHP Tutorial >一个关于json_decode()后显示为空的有关问题

一个关于json_decode()后显示为空的有关问题

WBOY
WBOYOriginal
2016-06-13 12:07:211070browse

一个关于json_decode()后显示为空的问题
代码如下,$data未转码之前还是正常的json格式数据,一转码直接变成Null了,求教大神帮忙看看是什么问题啊

header("Content-type:text/html;charset=utf-8");<br />$url = "http://218.22.201.163/wic/api.php/early_warning/xcyjservice/U/administrator/P/wic/jw/118.589036,30.055954";<br />       $postUrl = str_replace(' ', '%20', $url);<br />	   $param = '';<br />        $curlPost = $param;<br />        $ch = curl_init();<br />        curl_setopt($ch, CURLOPT_URL, $postUrl);<br />        curl_setopt($ch, CURLOPT_HEADER, 0);<br />        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br />        curl_setopt($ch, CURLOPT_POST, 1);<br />        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);<br />        curl_setopt($ch, CURLOPT_TIMEOUT, 60);<br />        $data = curl_exec($ch);<br />	<br />        curl_close($ch);<br />        //var_dump($data);die;//<br />        var_dump(json_decode($data, true));

------解决思路----------------------
你那个连接又 BOM 头!
json_decode(substr($data, 3), true)
就可以了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn