Reputation: 1213
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&sensor=false");
?>
Upvotes: 6
Views: 17801
Reputation: 5452
you almost had it!
<?php
$jsonObject = json_decode(file_get_contents("http://maps.google.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false"));
?>
Upvotes: 19
Reputation: 892
Nathan has it. You may want to explore the curl library for a more robust HTTP request approach, too.
Upvotes: 0