views:

26

answers:

2

From within PHP, how can I call an external JSON web service and then decode the returned string?

For example (pseudo-code):

<?php

$var jsonStr = json_decode("http://maps.google.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&amp;sensor=false");

?>
+2  A: 

you almost had it!

<?php
$jsonStr = json_decode(file_get_contents("http://maps.google.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&amp;sensor=false"));
?>
nathan
obviously this is a v simple implementation with no error checking or anything really, but it answers the question
nathan
A: 

Nathan has it. You may want to explore the curl library for a more robust HTTP request approach, too.

Funkatron