Antonis
Antonis

Reputation: 195

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: enter image description here

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.

Upvotes: 1

Views: 47

Answers (1)

Ali Khalili
Ali Khalili

Reputation: 1694

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

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

Upvotes: 2

Related Questions