0

I got a JSON from an URL like this:

http://myweb.com/ws_clc/ws_info.php?uid=77317

JSON:

{  
   "status":1,
   "info":[  
      {  
         "uid":"77317",
         "name":"Jack",
         "lastname":"Black",
         "email":"jackblack@mail.com"
      }
   ]
}

I need to format that JSON on HTML. ¿How can I do that?

THANKS!!! I did it like this:

<?php
$uid =$_GET['uid'];
$json = file_get_contents('http://myweb.com/ws_clc/ws_info.php?uid='.$uid);
$obj = json_decode($json);
$uid= $obj->info[0]->uid;
$name = $obj->info[0]->name;
$lastname = $obj->info[0]->lastname;

echo $name;
echo $lastname;
?>
Rodrick
  • 595
  • 10
  • 27
  • 1
    By using `json_decode()` and rendering the resulting structure any way you like. – arkascha Apr 28 '17 at 16:15
  • Bunch of results for this question on SO! Did you check them? Do you need anything specific? – szako Apr 28 '17 at 16:19
  • I am not sure how to use json_decode in this case. I edited the question with my try. I am close? – Rodrick Apr 28 '17 at 16:28
  • So your first problem is with retrieving the content? Rephrase your question then. The URL redirects me to the main page when opening in browser, you may need authentication before accessing the JSON data. Tell us what kind of service is this. Some kind of webservice? – szako Apr 28 '17 at 16:33
  • Yes, my problem is about retrieving the content. The URL is not the real URL, is just an example. Is a webservice.The real one is http://seminarioscorma.cl/ws_clc/ws_info.php?uid=77317 – Rodrick Apr 28 '17 at 18:34
  • 1
    Easiest and fastest way is to use [file_get_contents()](http://php.net/manual/en/function.file-get-contents.php), using stream contexts, see example #4. Next step would be using [curl](http://php.net/manual/en/book.curl.php) or something more robust for error checking. – szako Apr 28 '17 at 19:13

0 Answers0