赞
踩
有四种写法
①全索引数组:$json = '[["gemma",22],["huqin",23]]';
$jsontoobj = json_decode($json);
var_dump($jsontoobj);
②第一层索引,内层关联:$json2 = '[{"name":"gemma","age":22},{"name":"huqin","age":23}]';
$jsontoobj2 = json_decode($json2,true);
var_dump($jsontoobj2);
③第一层关联,内层索引:$json3 = '{"stu1":["gemma",22],"stu2":["huqin",23]}';
$jsontoobj3 = json_decode($json3,true);
var_dump($jsontoobj3);
④全关联数组:$json4 = '{"stu1":{"name1":"gemma","age":22},"stu2":{"name":"huqin","age":23}}';
$jsontoobj4 = json_decode($json4,true);
var_dump($jsontoobj4);
反正只要json格式数据有带{}的,如果想要转成数组,json_decode就需要第二个参数并且为true。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。