PHP Curl Json Response


I am in the process of building a call to a rest service.  I am correctly making the calls to the service etc, but I am having a slight issue with pulling specific data out.

Given the below response:

[{"created":"Fri, 08 Dec 2017 03:34:55 +0000",
"message":"SAMPLE MSG",
"receipts":{"delivered":"Fri, 08 Dec 2017 03:34:58 +0000"}}],"message":"Response follows","api_version":"2016-11-30","status":200,"uri":"\/2016-11-30\/sms\/cf4083fd852758af8bca5cffb77771d7"}"

Open in new window

This is what I am attempting to use to seperate out the receipts:
$Callresult = json_decode($response);
echo "attempt 1:".$response->sms_messages[0]->receipts;

But I keep getting an error of:
Notice:  Trying to get property of non-object

and if I try:
echo "attempt 1:".$response->sms_messages[0]->receipts;
i get:
Catchable fatal error:  Object of class stdClass could not be converted to string

if anyone could help it would be most appreciated!!!
mavmanauNetwork Engineer/SysadminAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
receipts is an object with a propery called delivered so you can't just echo out receipts. You'll need to echo out the property:

echo "attempt 1:".$response->sms_messages[0]->receipts->delivered;
Chris StanyonWebDevCommented:
Also, it's the raw JSON that is called $response. You are converting that into an objet called $Callresult, so actually what you need is this:

echo "attempt 1:".$Callresult->sms_messages[0]->receipts->delivered;
mavmanauNetwork Engineer/SysadminAuthor Commented:

I just realised that I did vardump on $response rather than the vardump of $Callresult.

it looks like this:

object(stdClass)#4 (7) {
  array(1) {
    object(stdClass)#5 (7) {
      string(31) "Fri, 08 Dec 2017 03:34:55 +0000"
      string(32) "cf4083fd852758af8bca5cffb77771d7"
      string(10) "0419000000"
      string(11) "61417000000"
      string(147) "SAMPLE MSG"
      string(48) "/2016-11-30/sms/cf4083fd852758af8bca5cffb77771d7"
      object(stdClass)#6 (1) {
        string(31) "Fri, 08 Dec 2017 03:34:58 +0000"
  string(16) "Response follows"
  string(10) "2016-11-30"
  string(48) "/2016-11-30/sms/cf4083fd852758af8bca5cffb77771d7"

given that result, how would I best access the receipts section?
Chris StanyonWebDevCommented:
I've already shown you how to access the receipts:


Have a read back through my previous answers.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mavmanauNetwork Engineer/SysadminAuthor Commented:
many thanks for your help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.