$a = ' {"Head": {"id": "4", "Userno": "12345", "username": "CDZ1"}, "Body": [{"OrderNo": "1", "Price": "15.00", "qty": "1"},{" OrderNo ":" 1 "," Price ":" 9.00 "," Qty ":" 1 "}]} ';
For such a jsoin, I have to get the field value of the head part and the field value of the body part separately, such as the Userno of the head part, and the price of the body part.
Reply to discussion (solution)
You Print_r (Json_decode ($a, 1)); Look, you know how to get the weight.
You Print_r (Json_decode ($a, 1)); Look, you know how to get the weight.
return this,
Array ([head] = = Array ([id] = 4 [Userno] = 13538750770 [Username] = CDZ1) [body] = = Array ([0] => ; Array ([OrderNo] = 1 [Price] = 15.00 [Qty] + 1) [1] = = Array ([OrderNo] = 1 [Foodno] = 3 [Price] = 9.00 [Qty] + 1)) Array ([0] = orange [1] = banana [2] + apple [3] = raspberry)
Circus Master Help.
The data you want is not taken out of such an array, your teacher should have spanked.
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 ', ),) ,)
Head->userno;echo '
Price: '. $obj->body[0]->price;/////or: Echo '
"; $ary =json_decode ($a, true); Echo ' Userno: '. $ary [' head '] [' Userno '];echo '
Price: '. $ary [' body '][0][' price '];? >
Using Json_decode (), you can convert the JSON data format and then call it in the form of an array.