我试图通过jquery读取一份json文件,然后把他放到php中进行动态布局并输出。现在遇到一个问题,就是我不知道如何将函数读取到的json中的参数值保存下来,然后用php读到这些值。希望有哪位朋友知道可以给与帮助(最好有代码)。
首先,json文件格式如下:
[
{
"counter": "0",
"contentID": "5876",
"score": "1.20501602970259",
"presentationID": "3496",
"conferenceID": "85",
"title": "Personalized Network Updates: Increasing Social Interactions and Contributions in Social Networks",
"acmlink": "null",
"DOI": "http://www.springerlink.com/content/872x206h570ln625/fulltext.pdf",
"contentType": "Long Research Paper",
"contentTrack": "1",
"authors": [
{
"authorID": "160",
"name": "Shlomo Berkovsky"
}
,
{
"authorID": "155",
"name": "Jill Freyne"
}
,
{
"authorID": "2947",
"name": "Gregory Smith"
}
],
"tags": ["3545", "contribution", "evaluation", "motivation", "news feed", "personalisation", "personalization", "personalized news feeds", "ranking", "recommender", "recsys", "shlomo berkovsky", "sna", "social network", "social networks", "social-network"],
"methodID": [0, 102, 101]
}
,
{
"counter": "1",
"contentID": "5883",
"score": "0.984497667264824",
"presentationID": "3503",
"conferenceID": "85",
"title": "Users and Noise: Estimating the Magic Barrier of Recommender Systems",
"acmlink": "null",
"DOI": "http://www.springerlink.com/content/g70242127h5kj186/fulltext.pdf",
"contentType": "Long Research Paper",
"contentTrack": "1",
"authors": [
{
"authorID": "3120",
"name": "Alan Said"
}
]
我用jquery读取json文件的代码:
$(function()
{
$("#btn").click(function()
{
$.getJSON("communityRecSys.json",function (data)
{
var $jsontip = $("#jsonTip");
var strHtml = " ";//存储变量
$jsontip.empty();//清空内容
$.each(data,function (infoIndex,info)
{
strHtml += "title:"+info["title"]+"
";
strHtml += "Authors:"+info["authors"]+"
";
strHtml += "Types:"+info["type"]+"
";
strHtml += "Track:"+info["contentTrack"]+"
";
strHtml += "DOI:"+info["DOI"]+"
";
strHtml += "
"
//这里只取了几个需要的值
});
});
});
});
然后在PHP中用这段代码测试,值能够正常显示:
说明值已经正常被读入。
下面是我希望进行php布局的代码。(proceedings是对每个模块的命名,method是我想用来代表json文件自己设的变量名称)
foreach( $proceedings as $method) {
<tr id="paper-<?php echo $method['contentID'];?>">
<tr>
<td style="background-color:#FFFF00;"> </td>
<td colspan="1" rowspan="5" name="paper" style="padding:5px;background-color:white">
<?php echo "<div class=\"title\"><div class=\"presentation-title\" ><span class=\"paper-title\"><a id=\"title-".$method['contentID']."\" href=\"presentation2.php?conferenceID=".$method['conferenceID']."&presentationID=".$method['presentationID']."\">".$method['title']."</a></span>"; ?>
请问怎么样能够把函数读到的json文件用变量$method保存,这样所有json内的参数我就可以用method.XX的方式直接取到值。感谢大神赐教!
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。