phpjsonjquery
我试图通过jquery读取一份json文件,然后把他放到php中进行动态布局并输出。现在遇到一个问题,就是我不知道如何将函数读取到的json中的参数值保存下来,然后用php读到这些值。希望有哪位朋友知道可以给与帮助(最好有代码)。
首先,json文件格式如下:
[
<code>{ "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" }</code>
]
我用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) {
<code><tr id="paper-<?php echo $method['contentID'];?>"> </tr> <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="%5C%22presentation2.php?conferenceID=%22.%24method%5B'conferenceID'%5D.%22&presentationID=%22.%24method%5B'presentationID'%5D.%22%5C%22">".$method['title']."</a></span>"; ?><p>请问怎么样能够把函数读到的json文件用变量$method保存,这样所有json内的参数我就可以用method.XX的方式直接取到值。感谢大神赐教!</p> </div> </td> </tr></code>