日期:2014-05-17 浏览次数:20486 次
<?php $json=<<<JSON {data:[{code:"现货黄金",newPrice:"1662.3",hight:"0",low:"0",buy:"1662.3",sell:"r1663.3",zhang:"r4.75",date:"4:59:40",open:"0",close:"1657.55"}, {code:"香港黄金",newPrice:"15384",hight:"0",low:"0",buy:"15384",sell:"r15390",zhang:"r44",date:"2:59:55",open:"0",close:"15340"}, {code:"现货白银",newPrice:"31.25",hight:"0",low:"0",buy:"31.25",sell:"r31.31",zhang:"r0.17",date:"4:56:10",open:"0",close:"31.08"}, {code:"现货白金",newPrice:"1566.75",hight:"0",low:"0",buy:"1566.75",sell:"r1576.75",zhang:"r2.01",date:"3:29:35",open:"0",close:"1564.74"}, {code:"现货钯金",newPrice:"677.23",hight:"0",low:"0",buy:"677.23",sell:"r684.23",zhang:"r9.54",date:"3:29:35",open:"0",close:"667.69"}]} JSON; $json=preg_replace_callback('/(,|,?\s*?{)\b(\w+):/','callback',$json); print_r(json_decode($json,true)); function callback($v){ return "{$v[1]}\"{$v[2]}\":"; }
------解决方案--------------------
$json=preg_replace('/(,|,?\s*?{)\b(\w+):/', '$1"$2":',$json);
print_r(json_decode($json,true));
------解决方案--------------------
还是老大威武
2楼的修改下就可以了 ({|,)([^:\s]*)(?=:)