用laravel的GuzzleHttp写一个爬虫,抓.net接口的数据,返回为jsonp去掉函数后的字符串如下[{ gid:"10000",gname:"一汽奥迪",gspell:"yiqiaodi",child:[{"id":"3999","name":"A3","urlSpell":"aodia3-3999","showName":"奥迪A3","saleState":"在销"}]}]如何将此字符串转成php的数组?
2 回答
绝地无双
TA贡献1946条经验 获得超4个赞
$str = preg_replace(["/([a-zA-Z_]+[a-zA-Z0-9_]*)\s*:/", "/:\s*'(.*?)'/"], ['"\1":', ': "\1"'], $str); var_dump(json_decode($str,true));
qq_遁去的一_1
TA贡献1725条经验 获得超7个赞
[{ 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);
- 2 回答
- 0 关注
- 1193 浏览
添加回答
举报
0/150
提交
取消