I'm able to decode a json in php and below is the output using print_r($data)
.
stdClass Object
(
[sys_msg] => stdClass Object
(
[old_expiry_date] => 2015-06-25 00:00:00+00:00
[new_expiry_date] => 2015-12-25 00:00:00+05:30
[phone] => +919990321320
[userplan_id] => 65960
)
[user_msg] => SMEDELIVRY-38793
)
Now how do I parse this to get the details?
foreach($data as $data) {
echo "Expiry:".$data->old_expiry_date;echo "<br />";
Outputs the correct date but I'm not able to parse the [user_msg]
bit. I get an error:
Expiry:2015-06-25 00:00:00+00:00
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/sr/log.php on line 39
Expiry:
$data
is not an array, it's an object, there's nothing to loop over.
echo "Expiry: " . $data->sys_msg->old_expiry_date . "<br/>";
Your error is because the user_msg
property is a string, not an object, so it doesn't have an old_expiry_date
property. To show that, use:
echo "Message: " . $data->user_msg . "<br/>";