Home  >  Article  >  Backend Development  >  接收到的json解析不了,必须用php解析,该如何解决

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

WBOY
WBOYOriginal
2016-06-13 12:31:11663browse

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


function sendPost($url,$postData){
$postdata = http_build_query($postData);
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' => $postdata,
'timeout' => 15 * 60 // 超时时间(单位:s)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);

return $result;
}


$url = "http://chepiao.sinaapp.com/api.php?act=remain";
$data = array(
"date"=>"20131220",
"startStation"=>"北京",
"arriveStation"=>"天津"
);
$result = sendPost($url, $data);
$obj = json_decode($result);
$result就是返回来的数据,就是解析不了,用json_decode($result);解析成的是NULL

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