php调用返回json的webservice
<?php
$dbsrvr="localhost";
function get_recommend_media_by_id_ex($url)
{
global $dbsrvr;
$product_id = "4fbf28f148e65f7220c5f870";
$url = 'http://'.$dbsrvr.':8080/lct-shopping/api/shopping/recommenditems/'.$product_id;
$json = file_get_contents($url);
$list=json_decode($json,true);
return $list;
}
?>
例子中的
$url = 'http://'.$dbsrvr.':8080/lct-shopping/api/shopping/recommenditems/'.$product_id;
是要我访问的url,使用json_decode解析json格式的返回数据。
本文介绍了一种使用PHP脚本调用返回JSON格式数据的WebService的方法。通过示例代码展示了如何构造URL并利用file_get_contents获取数据,最后使用json_decode进行解析。
165

被折叠的 条评论
为什么被折叠?



