这一个数据怎样解析

xiachao2008 2011-12-20 08:54:00
我用了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"}))
...全文
120 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2011-12-21
  • 打赏
  • 举报
回复
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
[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
)




imbigsnake1 2011-12-21
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 helloyou0 的回复:]

这是jsonp
[/Quote]
乍看之下很像jsonp,不过多了一对括号
helloyou0 2011-12-20
  • 打赏
  • 举报
回复
http://api.jquery.com/jQuery.getJSON/
helloyou0 2011-12-20
  • 打赏
  • 举报
回复
这是jsonp
床上等您 2011-12-20
  • 打赏
  • 举报
回复
你这个不是json来的
xiachao2008 2011-12-20
  • 打赏
  • 举报
回复
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"}))

4,250

社区成员

发帖
与我相关
我的任务
社区描述
国内外优秀PHP框架讨论学习
社区管理员
  • Framework
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧