Received JSON parsing cannot, must use PHP parsing

Source: Internet
Author: User
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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.