The received json cannot be parsed and must be parsed using 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 // timeout (unit: s); $ context = stream_context_create ($ options); $ result = file_get_contents ($ url, false, $ context); return $ result;} $ url = "http://chepiao.sinaapp.c Om/api. php? Act = remain "; $ data = array (" date "=>" 20131220 "," startStation "=>" Beijing "," arriveStation "=>" Tianjin "); $ result = sendPost ($ url, $ data); $ obj = json_decode ($ result); $ result indicates that the returned data cannot be parsed, and json_decode ($ result) is used ); parsed to NULL
Reply to discussion (solution)
Help resolve
Print $ result to view the result
Really good.
See in the gbk environment
{"Title ":"Beijing-Tianjin?? 0 items splash? "," ErrMsg ":"???? Why? Why ?? Parameters ???? Xuan ?? "}
UTF-8 environment
{"Title ":"????-??
This post was last edited by xuzuning at 19:19:36, January 17 ,.
Even csdn cannot accept this character set disorder
UTF-8 environment
Amazing
Echo json_last_error ();
The result is 4, indicating that the format is incorrect.
So I threw the returned content at http://jsonlint.com/detection, and reported an error, which is a line change problem.
Print_r (json_decode (str_replace ("\ n", "", $ result )));
The result is fine.
Thank you for not using json_last_error.