The JSON data can be obtained from the micro-port in bulk, but the return is null (resolved) when converting to an array with Json_decode

Source: Internet
Author: User
https_request是调用第三方接口的方法。

Print $output is a value, can see the Access_token, but the printing $jsoninfo is empty, so the back of the return Access_token also get not

        $output =$this->https_request($url);            $jsoninfo = json_decode($output, true);            $access_token = $jsoninfo["access_token"];            return $access_token;             

The problem is resolved
Cause: In the method of acquiring a third-party interface, there are already json_decode

Reply content:

https_request是调用第三方接口的方法。

Print $output is a value, can see the Access_token, but the printing $jsoninfo is empty, so the back of the return Access_token also get not

        $output =$this->https_request($url);            $jsoninfo = json_decode($output, true);            $access_token = $jsoninfo["access_token"];            return $access_token;             

The problem is resolved
Cause: In the method of acquiring a third-party interface, there are already json_decode

That means json_decode it failed.
json_decodeafter json_last_error() that, use the function to see what the error is.

1. json字符串必须以双引号包含$output = str_replace("'", '"', $output);2. json字符串必须是utf8编码$output = iconv('gbk', 'utf8', $output);3.不能有多余的逗号 如:[1,2,]用正则替换掉,preg_replace('/,\s*([\]}])/m', '$1', $output)

Problems have been found, personal reasons

  • 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.