我已經使用這個代碼,以使json
對象需要進行多次JSON對象單一的文件在PHP
if(mysql_num_rows($result)) {
while($document = mysql_fetch_assoc($result)) {
$documents[] = $document;
}
}
header('Content-type: application/json');
echo json_encode(array('documents'=>$documents));
它給了我一個JSON文件這樣
{"document":[{"document":{"id":"2","name":"test","pages":"name","img":"path","lines":"data"}]}
但我需要
{"document":[{"document":{"id":"2","name":"test",pages":[{"img":"first img","lines":" <p>first line"}],pages":[{"img":"second img","lines":" <p>second line"}]}]}
現有json中的方法需要另一個json名稱包含更多img和line的頁面秒。 它是如何做到的?
*「表示在現有的JSON需要包含進一步的IMG和線另一JSON名字的網頁它該怎麼辦?」 *我很抱歉,但在英語中沒有任何意義。你可以再試一次嗎(也許請求同事幫忙?)。 – 2013-02-14 08:25:23
因此,在使用回聲之前,讓你的數組像你想要的..然後回聲它與json_encode .. – Pankaj 2013-02-14 08:34:18