Heim  >  Artikel  >  Backend-Entwicklung  >  接收到的json解析不了,必须用php解析,该如何解决

接收到的json解析不了,必须用php解析,该如何解决

WBOY
WBOYOriginal
2016-06-13 11:42:511254Durchsuche

接收到的json解析不了,必须用php解析

<br />function sendPost($url,$postData){<br /> $postdata = http_build_query($postData);<br /> $options = array(<br /> 'http' => array(<br /> 'method' => 'POST',<br /> 'header' => 'Content-type:application/x-www-form-urlencoded',<br /> 'content' => $postdata,<br /> 'timeout' => 15 * 60 // 超时时间(单位:s)<br />)<br /> );<br /> $context = stream_context_create($options);<br /> $result = file_get_contents($url, false, $context);<br /><br /> return $result;<br /> }<br /><br /><br />$url = "http://chepiao.sinaapp.com/api.php?act=remain";<br />$data = array(<br /> "date"=>"20131220",<br /> "startStation"=>"北京",<br /> "arriveStation"=>"天津"<br />);<br />$result = sendPost($url, $data);<br /> $obj = json_decode($result);<br />$result就是返回来的数据,就是解析不了,用json_decode($result);解析成的是NULL

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn