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