将PHP第二级json转换为数组
我正在尝试在数组中转换json数据,但第二级json数据未在数组中转换将PHP第二级json转换为数组,php,arrays,json,Php,Arrays,Json,我正在尝试在数组中转换json数据,但第二级json数据未在数组中转换 print_r($data); =>输出 id => 1 totalRecords => 2 info => {"id":1,"name":"abc"} Array ( [id] => 1 [totalRecords] => 2 [info] => {"id":1,"name":
print_r($data);
=>输出
id => 1
totalRecords => 2
info => {"id":1,"name":"abc"}
Array
(
[id] => 1
[totalRecords] => 2
[info] => {"id":1,"name":"abc"}
)
使用json
$data = json_decode(json_encode($data),true);
print_r($data);
=>输出
id => 1
totalRecords => 2
info => {"id":1,"name":"abc"}
Array
(
[id] => 1
[totalRecords] => 2
[info] => {"id":1,"name":"abc"}
)
但不转换数组中的数据{“id”:1,“name”:“abc”}。假设您有此数据数组:
print_r($data);
<?php
$data = [
'id' => 1,
'totalRecords' => 2,
'info' => [
'id' => 1,
'name' => 'abc'
]
];
print_r(json_decode(json_encode($data)));
?>
数据变量应具有此数组格式,以便正确转换。为什么不尝试:$Data['PassengerInfo']=json_decode($Data['PassengerInfo'],true)