php中输出json数组


output json array in php

我现在有这个json:

{"quest_id":"1","quest_title":"Buy 3 pints of draft and a large pizza and then get desert","quest_price":"15","quest_points":"100"}{"quest_id":"2","quest_title":"Hello WOrld","quest_price":"50","quest_points":"10"}

我想知道如何输出这个:

{"quests":  {"quest_id":"1","quest_title":"Buy 3 pints of draft and a large pizza and then get desert","quest_price":"15","quest_points":"100"}{"quest_id":"2","quest_title":"Hello WOrld","quest_price":"50","quest_points":"10"}
}
下面是php中的代码:
while($result=mysql_fetch_array($number, MYSQL_ASSOC)){
        print(json_encode($result));
    }

试试这个:

$result = array('quests' => array());
while($row = mysql_fetch_array($number, MYSQL_ASSOC)){
    $result['quests'][] = $row
}
echo json_encode($result);

如果我正确理解你想做什么,得到一个JSON数据包与所有的行,然后循环它们把它们放在一个数组,然后编码整个数组:

<?php
  $result = mysql_query($query);
  $out = array('quests' => array());
  while ($row = mysql_fetch_assoc($result)) {
      $out['quests'][] = $row;
  }
  print json_encode($out);
?>