Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将PHP第二级json转换为数组_Php_Arrays_Json - Fatal编程技术网

将PHP第二级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":

我正在尝试在数组中转换json数据,但第二级json数据未在数组中转换

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)