Ask how this JS data is decoded,
Ask how this JS data is decoded,
Data address: Http://list.taobao.com/itemlist/default.htm?_input_charset=utf-8&json=on&cat=0&style=grid &pcat=food2011&q=ps&rr=1&spm=a2106.m5221.1000187.1&commend=all&psize=95&_ksts= 1382516137021_144&callback=jsonp145
First of all, it's not working with PHP Json_decode.
Share to:
------Solution--------------------
This is JSONP, give you javascript call, use jquery Jsonp way request, own Baidu Bar, or write a
The principle is that the URL inside the callback parameter is your pre-defined function name
JS Bin
If you want PHP to request this link, remove the callback parameter
------Solution--------------------
$url = ' Http://list.taobao.com/itemlist/default.htm?_input_charset=utf-8&json=on&cat=0&style=grid &pcat=food2011&q=ps&rr=1&spm=a2106.m5221.1000187.1&commend=all&psize=95&_ksts= 1382516137021_144&callback=jsonp145 ';
$s = file_get_contents ($url);
Preg_match ('/{.+}/s ', $s, $r); He returns the JS function, so it needs to be bracketed.
$o = Json_decode (Iconv (' GBK ', ' utf-8 ', $r [0]), true);//His data is GBK, but Json_decode can only handle utf-8 functions
Print_r ($o);
Array
(
[Status] = Array
(
[Code] = 200
[url] = =
)
[crumb] = = Array
(
[Marketinfo] = = Array
(
[DisplayName] = ALL markets
[Markethref] = http://list.taobao.com/cat-0.htm
)
[Catpathlist] = = Array
(
)
)
[keyword] = = Array
(
[Key] = Q
[Value] = PS
)
[Sort2list] =
[Promotion] = = Array
.....