-1

I want to do the following in PHP:

Get json data from http://domain.com/api/user/1

This provides:

{"name":"Joe","password":"something","email":"something@something.com"}

I want to be able to do a simple php echo to display the json data on a webpage

<html><?php echo $password ?></html>
<html><?php echo $name ?></html>
<html><?php echo $email ?></html>

So basically, creating a php for the "name" / "password" or "email" part of json results

1 Answers1

0

You can do like this:

<?php

$json = '{"name":"Joe","password":"something","email":"something@something.com"}';

$obj = json_decode($json);
print $obj->{'name'}; // Joe
print $obj->{'password'}; // something
print $obj->{'email'}; // something@something.com

?>

for more info: http://in1.php.net/json_decode

Suresh Kamrushi
  • 15,627
  • 13
  • 75
  • 90