在php中 如何把js对象转成数组?

  1. laravelGuzzleHttp写一个爬虫,抓.net接口的数据,返回为jsonp

  2. 去掉函数后的字符串如下

[{ gid:"10000",gname:"一汽奥迪",gspell:"yiqiaodi",child:[{"id":"3999","name":"A3","urlSpell":"aodia3-3999","showName":"奥迪A3","saleState":"在销"}]}]
  1. 如何将此字符串转成php的数组?


千巷猫影
浏览 1194回答 2
2回答

绝地无双

$str = preg_replace(["/([a-zA-Z_]+[a-zA-Z0-9_]*)\s*:/", "/:\s*'(.*?)'/"], ['"\1":', ': "\1"'], $str); var_dump(json_decode($str,true));

qq_遁去的一_1

[{ 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);
打开App,查看更多内容
随时随地看视频慕课网APP