用laravel的GuzzleHttp写一个爬虫,抓.net接口的数据,返回为jsonp去掉函数后的字符串如下[{gid:"10000",gname:"一汽奥迪",gspell:"yiqiaodi",child:[{"id":"3999","name":"A3","urlSpell":"aodia3-3999","showName":"奥迪A3","saleState":"在销"}]}]如何将此字符串转成php的数组?
2 回答
有只小跳蛙
TA贡献1824条经验 获得超8个赞
$str=preg_replace(["/([a-zA-Z_]+[a-zA-Z0-9_]*)\s*:/","/:\s*'(.*?)'/"],['"\1":',':"\1"'],$str);var_dump(json_decode($str,true));
ABOUTYOU
TA贡献1812条经验 获得超5个赞
[{gid:"10000",gname:"一汽奥迪",gspell:"yiqiaodi",child:[{"id":"3999","name":"A3","urlSpell":"aodia3-3999","showName":"奥迪A3","saleState":"在销"}]}]这个本身不是php标准的json字符串,key值没有引号。$data='[{"gid":"10000","gname":"一汽奥迪","gspell":"yiqiaodi","child":[{"id":"3999","name":"A3","urlSpell":"aodia3-3999","showName":"奥迪A3","saleState":"在销"}]}]';$result=json_decode($data,true);var_dump($result);
添加回答
举报
0/150
提交
取消