php-jquery函數 讀取 json 檔案後的運用

來源:互聯網
上載者:User
關鍵字 php json jquery
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的方式直接取到值。感謝大神賜教!

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.