問一下這個JS資料怎麼解碼

來源:互聯網
上載者:User
問一下這個JS資料如何解碼,
問一下這個JS資料如何解碼,

資料地址: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


先聲明,用php的json_decode是不行的哦

分享到:


------解決方案--------------------
這是jsonp,給你javascript調用的 ,用jquery的jsonp方式請求,自己百度吧,或者自己寫一個
原理就是url裡面callback參數是你預先要定義的函數名




JS Bin







你如果要php請求這個連結,就把callback參數去掉

------解決方案--------------------
$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); //他返回的是js函數,所以需要脫括弧
$o = json_decode(iconv('gbk', 'utf-8', $r[0]), true);//他的資料是gbk的,但json_decode只能處理utf-8的函數
print_r($o);
Array
(
[status] => Array
(
[code] => 200
[url] =>
)

[crumb] => Array
(
[marketInfo] => Array
(
[displayName] => 所有市場
[marketHref] => http://list.taobao.com/cat-0.htm
)

[catPathList] => Array
(
)

)

[keyword] => Array
(
[key] => q
[value] => ps
)

[sort2List] =>
[promotion] => Array
.....
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.