时间:2021-07-01 10:21:17 帮助过:54人阅读
array (
'head' => array (
'id' => '4',
'userno' => '12345',
'username' => 'CDZ1',
),
'body' => array (
0 => array (
'orderno' => '1',
'price' => '15.00',
'qty' => '1',
),
1 => array (
'orderno' => '1',
'price' => '9.00',
'qty' => '1',
),
),
)
@header("Content-type: text/html; charset=utf-8");
$a='{"head":{"id":"4","userno":"12345","username":"CDZ1"},"body":[{"orderno":"1","price":"15.00","qty":"1"},{"orderno":"1","price":"9.00","qty":"1"}]}';
$obj=json_decode($a);
echo 'userno:'.$obj->head->userno;
echo '
price:'.$obj->body[0]->price;
/////或:
echo "
";
$ary=json_decode($a,true);
echo 'userno:'.$ary['head']['userno'];
echo '
price:'.$ary['body'][0]['price'];
?>