![](/img/trans.png)
[英]Swift - How can I read a two-dimensional array produced with json_encode?
[英]json_encode on a two-dimensional array
我在使用JSON和數組時遇到問題。
這是我的代碼:
while($row = mysql_fetch_assoc($result)){ echo json_encode($row); }
結果是:
{"id":"1","title":"event1","start":"2009-11-10 14:18:15","end":"2009-11-03 14:38:22","allDay":"false","url":null}{"id":"2","title":"event2","start":"2009-11-09 15:41:20","end":"2009-11-10 16:41:25","allDay":"false","url":null}
但是我希望結果看起來像這樣:
[{"id":"1","title":"event1","start":"2009-11-10 14:18:15","end":"2009-11-03 14:38:22","allDay":"false","url":null},{"id":"2","title":"event2","start":"2009-11-09 15:41:20","end":"2009-11-10 16:41:25","allDay":"false","url":null}]
我該怎么做?
$arr = array();
while($row = mysql_fetch_assoc($result)) {
$arr[] = $row;
}
echo json_encode($arr);
$myjsons = array();
while($row = mysql_fetch_assoc($result)){
$myjsons[] = json_encode(array($row));
}
print_r($myjsons);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.