adalli2008 2014-02-02 00:54 采纳率: 0%
浏览 2912

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

我试图通过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;">&nbsp;</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的方式直接取到值。感谢大神赐教!

  • 写回答

2条回答

  • lt318025 2014-03-04 01:51
    关注

    ajax我能想到的就是这个

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题