Ask how to decode this JS data

Source: Internet
Author: User
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
.....

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.