Reputation: 1937
I have this data
$result = json_decode(curl_exec($ch));
print_r($result);
// stdClass Object ( [d] => {"id":10} )
$id = ?;
How can I get a value of id?
Upvotes: 1
Views: 41
Reputation: 9199
You would get value with following
$obj_result = json_decode($result->d);
echo $obj_result->id;
By this way you will get id value 10
Upvotes: 0
Reputation: 780724
Since $result
is an object, you have to use property notation to access its components.
$id = json_decode($result->d)->id;
You need the extra json_decode
because the value of $result->d
is another JSON string, not an object or array.
Upvotes: 2