我尝试在数组中转换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"}。
答案 0 :(得分:0)
假设您拥有此数据阵列:
<?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 ) )
Data var应具有此数组格式,以便正确转换。