Ask how to decode this JS data, ask how to decode this JS data, data address: http://list.taobao.com/itemlist/default.htm? _ Input_charset = UTF-8 & amp; json = on & amp; cat = 0 & amp; style = grid & amp; pcat = food ask how to decode this JS data,
Ask how to decode the JS data,
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 declare that json_decode in php cannot be used. share it:
------ Solution --------------------
This is jsonp, which is called by javascript. it is requested in the jsonp method of jquery. you can use Baidu or write
The principle is that the callback parameter in the url is the function name you want to define in advance.
JS Bin
function jsonp145(data){
alert(data.status.code);//200
}
《script》
《script》
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); // The js function is returned, so parentheses are needed.
$ O = json_decode (iconv ('gbk', 'utf-8', $ r [0]), true); // its data is gbk, however, json_decode can only process UTF-8 functions.
Print_r ($ o );
Array
(
[Status] => Array
(
[Code] = & gt; 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
.....