David McClave
David McClave

Reputation: 167

Confused about json_decode and results I'm getting

I have a simple script that gets a json result:

$postURL = $URL;
$json = file_get_contents($postURL);
$obj = json_decode($json);
print_r ($json);

the print_r gives me a blank, as does echo $obj->{'name'}

I suspect I may be handling the result improperly. I need help - just need to be able to grab a single key/value from the object using $obj->{'name'}.

My result from file_get_contents looks like this:

GET d41d8cd98f00b204e9800998ecf8427e Mon, 16 Dec 2013 09:47:07 GMT 
/targets/32feaf056b8c46e4a6f5500b6289cf59{"target_record":
{"target_id":"32feaf056b8c46e4a6f5500b6289cf59","name":"Francesca
Grace","width":300.0,"active_flag":true,"tracking_rating":5,"reco_rating":""},
 "status":"success","result_code":"Success",
"transaction_id":"d5f6be0a66af4e3d84d00ad4cb1ac2e3"}

Upvotes: 0

Views: 61

Answers (2)

Mazeltov
Mazeltov

Reputation: 551

here is an example of json with google rates system:

$data = file_get_contents('http://rate-exchange.appspot.com/currency?from=GBP&to=EUR');
$resultat = json_decode($data, true);
echo $resultat["rate"];

Upvotes: 1

Jacob A.
Jacob A.

Reputation: 270

$postURL = $URL;
$json = file_get_contents($postURL);
$obj = json_decode($json);
print_r ($obj);

Upvotes: 0

Related Questions