0

I have the following JSON object which I have decoded. I know that to access the data from the object, you would normally:

$value = $obj->data

Consider the following, where is a variable returned from the curl request

stdClass Object
(
    [<account_name>] => stdClass Object
    (
        [id] => 123
        [name] => "Some Name"
        [email] = "[email protected]"
    )
)

How do I get the values of [id], [name], [email] etc, if I do not know the object key?

1
  • 1
    Use json_decode($json,true); it will give you an array then lopp through and useing foreach($data as $key=>$val) you will get the data. Commented Feb 20, 2014 at 7:59

2 Answers 2

4

If you use json_decode, set the second parameter to true to decode the json data to an array.

Then you could use foreach to loop the array even you do not know the key.

Sign up to request clarification or add additional context in comments.

Comments

0

This function will most likely be able to help you. Get_Object_vars

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.