Taobao mobile phone number Attribution API

Source: Internet
Author: User

https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=13001631234
PHP cannot parse JSON strings after using this interface to query the attribution information
Php

    $ch = curl_init();    $url = "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=$mobile"."&t=".time();    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    // 执行HTTP请求    curl_setopt($ch, CURLOPT_URL, $url);    $res = curl_exec($ch);    $res = trim(explode('=',$res)[1]);    $res = iconv('gbk','utf-8', $res);    var_dump($res);    $res = json_decode($res, true);    var_dump($res);

Reply content:

https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=13001631234
PHP cannot parse JSON strings after using this interface to query the attribution information
Php

    $ch = curl_init();    $url = "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=$mobile"."&t=".time();    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    // 执行HTTP请求    curl_setopt($ch, CURLOPT_URL, $url);    $res = curl_exec($ch);    $res = trim(explode('=',$res)[1]);    $res = iconv('gbk','utf-8', $res);    var_dump($res);    $res = json_decode($res, true);    var_dump($res);

-Resolved

Found by Json_last_error () is json_error_syntax: '-SYNTAX error, malformed JSON '

Then the key is connected "" to expand it.

    $res = trim(explode('=',$res)[1]);    $res = iconv('gbk','utf-8', $res);    $res = str_replace("'",'"', $res);    $res = preg_replace('/(\w+):/is', '"$1":', $res);


It is recommended to change the interface, or the request is missing a parameter, the return is not JSON data

For PHP jsonp to turn json , not directly after the finished.

下面是官方文档的说明:
  
   

Official Document Entry Json-decode

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