K
K
KronosHD2015-08-24 09:41:22
PHP
KronosHD, 2015-08-24 09:41:22

How to get JSON response?

This code should receive JSON and then decode it, and output it online to site.ru/?online. So why doesn't it work?

$server = @file_get_contents('http://api.minetools.eu/ping/lobby.freecraft.eu/25565');
$tree = json_decode($server);
if(isset($_REQUEST['online'])){ 
exit("{$tree['players']['online']}");
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-08-24
@KronosHD

1. Check that the data is written to $server
2. json_decode([json], true) - the true flag sets json parsing into an array, now you have an object after json_decode $tree.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question