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 ' =& Gt 15 * 60//Time-out (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" = "20131220", "startstation" = "Beijing "," Arrivestation "and" Tianjin "); $result = Sendpost ($url, $data); $obj = Json_decode ($result), $result is the data returned, is not resolved, with Json_decode ($result); parse to null
Reply to discussion (solution)
Somebody help me to analyze
Print the next $result look at the results
That's good enough.
GBK Environment to see
{"title": " Beijing - Tianjin ??" 0 RAO ¤ Splash 锛? "," ErrMsg ":"???? -Hi? 锛?? ³ã???? ?? "}
Utf-8 Environment to see
{"title": "???? - ??
This post was last edited by xuzuning on 2013-12-17 19:19:36
Even Csdn can't accept this character set's insanity.
Utf-8 Environment to see
It's wonderful.
Echo Json_last_error ();
The result is 4, stating that the format is incorrect
So the return of the things to throw http://jsonlint.com/detection, error, found to be the problem of a newline
Print_r (Json_decode (str_replace ("\ n", "", $result)));
The result is good.
Thank you Json_last_error didn't learn to use, knot paste