我有一个API的响应,它是一个字符串中的数组,我想在普通数组中格式化,任何帮助都很明显。
' [{" CODCHARGE":30.000," DockNo":" I31000106219"" OrderNo":&#34 ; 47735530""原因":"令 Nos上传成功!!","成功":"是"," TotalFreight":125.000}]'
我想从数组中删除第一个和最后一个qoutes。
format should be :-
[
{"CODCHARGE":30.000,
"DockNo":"I31000106219",
"OrderNo":"47735530",
"Reason":"Order Nos uploaded Successfully!!",
"Succeed":"Yes","TotalFreight":125.000
}
]
答案 0 :(得分:1)
使用json_decode(),如果要转换为数组,则辅助参数必须为true
或1
。
$string = '[{"CODCHARGE":30.000,"DockNo":"I31000106219","OrderNo":"47735530","Reason":"Order Nos uploaded Successfully!!","Succeed":"Yes","TotalFreight":125.000}]';
$array = json_decode( $string, true );
print_r($array);
转换后:
Array
(
[0] => Array
(
[CODCHARGE] => 30
[DockNo] => I31000106219
[OrderNo] => 47735530
[Reason] => Order Nos uploaded Successfully!!
[Succeed] => Yes
[TotalFreight] => 125
)
)