0

I cannot find how to get the results from this JSON post in PHP.

    stdClass Object
(
    [api_job_id] => 398438bf-c0a5-46fc-8774-70d2425e1ce7
    [data] => Array
        (
            [0] => stdClass Object
                (
                    [type] => MESSAGE
                    [message_id] => 15125005817130024103
                    [to] => xxx
                    [error_code] => 0
                    [#meta] => stdClass Object
                        (
                            [error] => stdClass Object
                                (
                                    [error_desc] => NO_USER
                                    [error_code] => 9
                                )

                        )

                )

        )

)

as you can see the meta has a # icon before it.

I can read all data to vars instead of the data in the #meta

I tried many ways like: $result = $arrayResponse['#meta']['error']['error_desc']; it's not working in PHP because of the # icon.

Any idea how I can get the values from these errors in #meta?

1
  • Can you post what you have come up with? it will help us better understand what you may be missing Commented Dec 5, 2017 at 19:21

1 Answer 1

2

To refer to an object attribute with a name that doesn't make a valid variable, you can use braces:

$foo = json_decode($string);
var_dump($foo->{'#meta'});

Or pass a truthy value to json_decode() as the second argument, and you'll get back an array instead of an object:

$foo = json_decode($string, true);
var_dump($foo['#meta']);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.