简体   繁体   中英

Display a specific value of Json in PHP

I would like to add a specific value of JSON in a variable and then print it.My code is:

$jd_user = json_decode($result);
print_r($jd_user);

And the result of this is: 在此处输入图像描述

I want to print the highlight of the above picture CU26943

I try:

$client=$jd_user->data->user;
echo $client; 

But I receive error:

Trying to get property of non-object in (..)

Any suggestions? Thanks in advance.

The data is an array not an object. You should use:

$jd_user = json_decode($result);
$client=$jd_user->data[0]->user;
echo $client;

Try this out:

$jd_user = json_decode($result, true); // true to get raw array 
$client=$jd_user['data'][0]['user'];
echo $client;

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