简体   繁体   中英

php how get a value of json?

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM