我尝试在数组中转换json数据,但二级json数据没有在数组中进行转换。
print_r($data);
=>输出
id => 1
totalRecords => 2
info => {"id":1,"name":"abc"}
使用json
$data = json_decode(json_encode($data),true);
print_r($data);
=>输出
Array
(
[id] => 1
[totalRecords] => 2
[info] => {"id":1,"name":"abc"}
)
但不转换数组中的数据{"id":1,"name":"abc"}。
假设您有这个数据数组:
<?php
$data = [
'id' => 1,
'totalRecords' => 2,
'info' => [
'id' => 1,
'name' => 'abc'
]
];
print_r(json_decode(json_encode($data)));
?>
它工作良好,输出为:
stdClass Object ( [id] => 1 [totalRecords] => 2 [info] => stdClass Object ( [id] => 1 [name] => abc ) )
数据变量应该具有此数组格式,以便正确转换。