开发者

How do I call and decode a JSON web service from PHP?

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");

?>


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"));
?>


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜