php - Connecting to database to retrieve and parse JSON data? -


i trying making basic html page 1 of professor's databases has. problem not know how data database , parse correctly. example, here have far. want print name of satellites.

<html> <head><title>testing</title></head> <body>  <p>this above php.</p>  <?php   $json = file_get_contents("https://db.satnogs.org/api/satellites/   ?format=json");   $data = json_decode($json);   echo $data->{"name"};  ?>  <p>this under php. </p> </body> </html> 

and gives me webpage says:

this above php.  under php. 

with data should between 2 lines missing. don't error, either. know there lot of resources answer question i've looked on stack overflow , other webpages , can't find answer helps me understand problem or solve it. also, i'm not quite sure if should using php. suggestion solve problem appreciated.

as can see, if visit website https://db.satnogs.org/api/satellites/?format=json, format json there's no name there.

{     "detail": "not found." } 

in scenario do...

echo $data->detail; 

you can decode json using arrays well, , more comprehensible parsed.

$data = json_decode($json, true); echo $data['detail']; 

update:

in fact, url has data if clean.

in case, result array of arrays :)

$data = json_decode($json, true); foreach ($data $item) {     echo $item['name'] . php_eol; } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -