I am parsing a JSON being posted from another website and one of the nodes has a child.
$inputJSON = file_get_contents('php://input');
$input= json_decode( $inputJSON); //convert JSON into object
$order_number = $input->{'order_no'};
$name = $input->{'name'};
$street_address = $input->{'address_1'};
$city =$input->{'city'};
$state = $input->{'region'} ;
$zip = $input->{'postal_code'};
I am being able to read all the values. However, the product section has the format
<items>
<product_code></product_code>
<product_name></product_name>
</items>
I am trying to read it as
$product_id = $input->{'items'}{'product_code'};
$product_description = $input->{'items'}{'product_name'};
But I am getting no data in my variables. What is the correct syntax?
Thanks.
Edit: The JSON output
object(stdClass)#1 (20) {
["test_order"]=>
string(1) "Y"
["shop_no"]=>
string(6) "142319"
["order_no"]=>
string(12) "TU5495467701"
string(5) "Smith"
["city"]=>
string(5) "Bosei"
["postal_code"]=>
string(6) "123456"
["order_total"]=>
string(5) "39.00"
["country"]=>
string(2) "HK"
["telephone"]=>
string(8) "12345678"
["pay_source"]=>
string(2) "CC"
["base_currency"]=>
string(3) "USD"
["items"]=>
array(1) {
[0]=>
object(stdClass)#2 (9) {
["product_price"]=>
string(5) "39.00"
["product_name"]=>
string(12) "Abcd Product"
["product_code"]=>
string(8) "142319-1"
}
}
["first_name"]=>
string(4) "John"
}