這一個資料怎麼解析

來源:互聯網
上載者:User
這一個資料怎樣解析
本帖最後由 xiachao2008 於 2011-12-20 20:54:23 編輯

我用了json
但是輸不出來動西,
當然也無法操作了。
我主要是想得到data[]裡面每一個資料。比如
我想得到。og_id 我應該怎麼操作呢????


public function getJson($url){
$str=file_get_contents($url);
$data=json_decode($str,true);
echo "
";print_r($data);exit();
return $data;
}

在瀏覽器裡找開啟串連是這樣的。

SINAFINANCE132436359014192800(({data:[{og_id:"1061971",contest_id:"8",sid:"2096647540",StockCode:"sz002230",StockName:"科大訊飛",SellBuy:"0",OrderPrice:"34.700",DealAmount:"4200",OrderAmount:"4200",IfDealt:"1",OrderTime:"2011-10-25 09:58:44",mtime:"2011-10-25 09:58:44",remark:""}],count:"100"}))

------解決方案--------------------
你這個不是json來的
------解決方案--------------------
這是jsonp
------解決方案--------------------
http://api.jquery.com/jQuery.getJSON/
------解決方案--------------------
本帖最後由 xuzuning 於 2011-12-21 10:33:58 編輯

1、不知道你的這個串是從哪裡來的,因為你沒給出出處
2、不知道什麼是 jsonp,但此串顯然不符合那個串連中的描述
3、但我知道這是一個js指令,他通過先前已載入過的 SINAFINANCE132436359014192800 函數進行某個操作。
4、我還知道,傳遞的 json 串是微軟系列語言使用的標準格式:鍵名沒有雙引號
這種格式的 json 不能被目前 php 的內建函數所接受,不能不說是個敗筆

js 分析
顯示

og_id:1061971
contest_id:8
sid:2096647540
StockCode:sz002230
StockName:科大訊飛
SellBuy:0
OrderPrice:34.700
DealAmount:4200
OrderAmount:4200
IfDealt:1
OrderTime:2011-10-25 09:58:44
mtime:2011-10-25 09:58:44
remark:
remark:undefined
remark:undefined
count:100

php 分析
$s =<<< JSON
{data:[{og_id:"1061971",contest_id:"8",sid:"2096647540",StockCode:"sz002230",StockName:"科大訊飛",SellBuy:"0",OrderPrice:"34.700",DealAmount:"4200",OrderAmount:"4200",IfDealt:"1",OrderTime:"2011-10-25 09:58:44",mtime:"2011-10-25 09:58:44",remark:""}],count:"100"}
JSON;
$s = iconv('gbk', 'utf-8', $s);
$s = preg_replace('/(\w+[a-z]):/i', '"$1":', $s);
print_r(json_decode($s));
顯示
stdClass Object
(
[data] => Array
(
[0] => stdClass Object
(
[og_id] => 1061971
[contest_id] => 8
[sid] => 2096647540
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.