日期:2014-05-17  浏览次数:20608 次

这一个数据怎样解析
本帖最后由 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 "<pre>";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 分析
<script>
function SINAFINANCE132436359014192800(v) {
  for(t in v) {
    if(typeof(v[t]) == 'object') SINAFINANCE132436359014192800(v[t])
    document.write(t + ':'+v[t]+'<br>');
  }
}

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"}))
</script>
显示

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
                    [