0

I want to get specific data values from json. Here is my json code

{"status":{"shipmentnumber":"5014402092","statusrow":[{"statusdate":"Mar 01st, 2021","statustime":"04:51 PM","statusmessage":"Delivered to "},{"statusdate":"Mar 01st, 2021","statustime":"07:08 AM","statusmessage":"Shipment has reached blueEX Gujranwala - Gujranwala"},{"statusdate":"Feb 26th, 2021","statustime":"10:43 PM","statusmessage":"Shipment is on route to Gujranwala"},{"statusdate":"Feb 26th, 2021","statustime":"10:42 PM","statusmessage":"Shipment reached blueEX Karachi Warehouse, Karachi"},{"statusdate":"Feb 26th, 2021","statustime":"03:36 PM","statusmessage":"Order information received, pending at Shipper's end."}]}}

I want to get "statusmessage": "Delivered to " data. Here is my code

$data['status']['statusrow'][0]['statusmessage']

But its returns { only.

Someone please guide what I did wrong

2 Answers 2

2

How are you converting the JSON string into a PHP data structure?

This works for me:

$json = '{"status":{"shipmentnumber":"5014402092","statusrow":[{"statusdate":"Mar 01st, 2021","statustime":"04:51 PM","statusmessage":"Delivered to "},{"statusdate":"Mar 01st, 2021","statustime":"07:08 AM","statusmessage":"Shipment has reached blueEX Gujranwala - Gujranwala"},{"statusdate":"Feb 26th, 2021","statustime":"10:43 PM","statusmessage":"Shipment is on route to Gujranwala"},{"statusdate":"Feb 26th, 2021","statustime":"10:42 PM","statusmessage":"Shipment reached blueEX Karachi Warehouse, Karachi"},{"statusdate":"Feb 26th, 2021","statustime":"03:36 PM","statusmessage":"Order information received, pending at Shipper\'s end."}]}}';
$data = json_decode( $json );

echo $data->status->statusrow[0]->statusmessage; // "Delivered to"
Sign up to request clarification or add additional context in comments.

Comments

0
$data = '{"status":{"shipmentnumber":"5014402092","statusrow":[{"statusdate":"Mar 01st, 2021","statustime":"04:51 PM","statusmessage":"Delivered to "},{"statusdate":"Mar 01st, 2021","statustime":"07:08 AM","statusmessage":"Shipment has reached blueEX Gujranwala - Gujranwala"},{"statusdate":"Feb 26th, 2021","statustime":"10:43 PM","statusmessage":"Shipment is on route to Gujranwala"},{"statusdate":"Feb 26th, 2021","statustime":"10:42 PM","statusmessage":"Shipment reached blueEX Karachi Warehouse, Karachi"},{"statusdate":"Feb 26th, 2021","statustime":"03:36 PM","statusmessage":"Order information received, pending at Shippers end."}]}}';


$data = json_decode($data,true);
// print_r($data)
echo $data['status']['statusrow'][0]['statusmessage'];

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.