我想在我的网页中显示JSON webservice的元素。这是我的服务响应
{"business":[{
"businessguid": "http:\/\/www.example.com/uploads/Facebook-ipo.jpg",
"businessposttitle": "Facebook ipo",
"omgguid": "http:\/\/www.samplesite.com\/?p=807",
"omgposttitle":"samplesite title"
}]}
我尝试使用Javascript解析该服务,我的代码是
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
$(function()
{
$(document).ready(function()
{
$.getJSON("insiders.php",function(data)
{
$.each(data,function(key,value){
var da ="<div ><a href="+value.businessguid+">"+value.businessposttitle+"</a></div>";
$(da).appendTo("#data_area");
});
}
);
return false;
});
});
</script>
</head>
<body>
<div id="data_area"></div></body>
但它没有显示我出错的地方.. ??
答案 0 :(得分:0)
<?php
$jdata = "http://www.example.com/myservicefile.php"; //Service URL
$content = file_get_contents($jdata);
$resultdiv = json_decode($content, true);
$businessdata=$resultdiv['business'];
foreach ($businessdata as $key => $value) {
echo '<span>'.$value[0].'</span></p>';
}
?>