$string = '[{"name":"Mobile Groups","value":1,"target":null,"alias":"mb_group","required":1,"showNull":0},
{"name":"Beta Group","value":3,"target":null,"alias":"mb_group","required":1,"showNull":0},
{"name":"Delta Group","value":4,"target":null,"alias":"mb_group","required":1,"showNull":0}]';
$array = json_decode($string);
var_dump($array);
输出
array (size=3)
0 =>
object(stdClass)[1]
public 'name' => string 'Mobile Groups' (length=13)
public 'value' => int 1
public 'target' => null
public 'alias' => string 'mb_group' (length=8)
public 'required' => int 1
public 'showNull' => int 0
1 =>
object(stdClass)[2]
public 'name' => string 'Beta Group' (length=10)
public 'value' => int 3
public 'target' => null
public 'alias' => string 'mb_group' (length=8)
public 'required' => int 1
public 'showNull' => int 0
2 =>
object(stdClass)[3]
public 'name' => string 'Delta Group' (length=11)
public 'value' => int 4
public 'target' => null
public 'alias' => string 'mb_group' (length=8)
public 'required' => int 1
public 'showNull' => int 0
你也可以得到带有TRUE
参数的数组转换对象:
$array = json_decode($string, true);