我有一个数组,我想将它转换为json,但它为一个字段返回null, 这是我的阵列:
[workname] => IŞIKLAR MÜHENDİSLİK
[workno] => 22330
[workdate] => Array
(
[0] => Array
(
[date] =>
[type] => ELEKTRİK
)
[1] => Array
(
[date] => 31.12.2007
[type] => ELEKTRİK
)
)
当我将其转换为json时,我将workdate元素视为null。
{"workname":"IŞIKLAR MÜHENDİSLİK","workno":"22330","workdate":null}
答案 0 :(得分:0)
$arr = array('workname' => 'IŞIKLAR MÜHENDİSLİK','workno' => 22330,'workdate' => array('0' => array('date' => '','type' => 'ELEKTRİK'),'1' => array('date' => '31.12.2007','type' => 'ELEKTRİK')));
echo json_encode($arr);
输出
{"workname":"I\u015eIKLAR M\u00dcHEND\u0130SL\u0130K","workno":22330,"workdate":[{"date":"","type":"ELEKTR\u0130K"},{"date":"31.12.2007","type":"ELEKTR\u0130K"}]}
你可以在这里查看http://sandbox.onlinephpfunctions.com/code/68c91d260a0a18d584dab871f56dd7c97482ca04
答案 1 :(得分:0)
$arr=array(
'workname' => 'IŞIKLAR MÜHENDİSLİK',
'workno' => 22330,
'workdate' => Array (
Array (
'date' => '',
'type' => 'ELEKTRİK'
),
Array(
'date' => '31.12.2007',
'type' => 'ELEKTRİK'
)
)
);
echo json_encode($arr);