The received json file cannot be parsed. you must use php to parse function & nbsp; sendPost ($ url, $ postData) {& nbsp; $ postdata & nbsp; http_build_query ($ postData); & nbsp; $ options & nbsp; array (& nbsp; http & nbsp; & gt; & the received json cannot be parsed, 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.com/api.php? Act = remain ";
$ Data = array (
"Date" = & gt; "20131220 ",
"StartStation" => "Beijing ",
"ArriveStation" => "Tianjin"
);
$ Result = sendPost ($ url, $ data );
$ Obj = json_decode ($ result );
$ Result is the returned data, that is, the data cannot be parsed, and json_decode ($ result) is used; the parsed result is NULL.
Share: More
------ Solution --------------------
This post was last edited by xuzuning at 19:19:36, January 17 ,.
Even csdn cannot accept this character set disorder
UTF-8 environment
------ Solution --------------------
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.