这一个数据怎么解析

WBOY
Release: 2016-06-13 12:59:23
Original
1015 people have browsed it

这一个数据怎样解析

本帖最后由 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();<br>
		return $data;<br>
	}<br>
<br>
在浏览器里找打开连接是这样的。<br>
<br>
<pre class="brush: Java">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"}))
Copy after login

------解决方案--------------------
你这个不是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><br />
function SINAFINANCE132436359014192800(v) {<br />
  for(t in v) {<br />
    if(typeof(v[t]) == 'object') SINAFINANCE132436359014192800(v[t])<br />
    document.write(t + ':'+v[t]+'<br>');<br />
  }<br />
}<br />
<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"}))<br />
</script>
Copy after login
显示

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<br />
{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"}<br />
JSON;<br />
$s = iconv('gbk', 'utf-8', $s);<br />
$s = preg_replace('/(\w+[a-z]):/i', '"$1":', $s);<br />
print_r(json_decode($s));
Copy after login
显示
stdClass Object<br>
(<br>
    [data] => Array<br>
        (<br>
            [0] => stdClass Object<br>
                (<br>
                    [og_id] => 1061971<br>
                    [contest_id] => 8<br>
                    [sid] => 2096647540 <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template