1

I am making a gaming panel with php where I need to read from a json api I have been reading on how to do this I need to get the value in the json api of banned

error_reporting(-1);
ini_set('display_errors', 'On');
$test = $steam->steamid;
$url = 'https://api.truckersmp.com/v2/player/' . $test;
$json = file_get_contents($url);
$api = json_decode($json);

echo $api->banned;

After running this I am receiving Notice:

Undefined property: stdClass::$banned in C:\xampp\htdocs\test.php on line 14

It should come back as a true or false value

I can view the array using var_dump

0

1 Answer 1

1

The PHP error is pretty straight forward, there is no property named banned ($api->banned).

So, looking at the json response, the banned property is inside the response property, so your echo should be:

echo $api->response->banned;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.