当前位置:Gxlcms > PHP教程 > php-jquery函数读取json文件后的运用

php-jquery函数读取json文件后的运用

时间:2021-07-01 10:21:17 帮助过:40人阅读

phpjsonjquery

我试图通过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) {

                     ".$method['title'].""; ?>

请问怎么样能够把函数读到的json文件用变量$method保存,这样所有json内的参数我就可以用method.XX的方式直接取到值。感谢大神赐教!

人气教程排行