php将json字符串转为数组的方法:可以利用json_decode函数来实现,如【json_decode($json, true);】。json_decode函数可以接受一个json格式的字符串并把它转换为php变量。
函数介绍:
(推荐教程:php视频教程)
json_decode接受一个JSON格式的字符串并且把它转换为PHP变量 ,当该参数$assoc为TRUE时,将返回array,否则返回object。
语法格式:
json_decode(string $json[,bool $assoc = false[,int $depth = 512[,int $options = 0]]])
代码实现:
<?php
$json = '{"a":"php","b":"mysql","c":3}';
$json_Class=json_decode($json);
$json_Array=json_decode($json, true);
print_r($json_Class);
print_r($json_Array);
?>输出结果:
stdClass Object ( [a] => php [b] => mysql [c] => 3 ) Array ( [a] => php [b] => mysql [c] => 3 )
Copyright © 2019- howto1234.net 版权所有
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务