本文介绍了二维阵列上json_en code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用JSON和数组的一个问题。
下面是我的code:
而($行= mysql_fetch_assoc($结果)){回声json_en code($行); }
的结果是:
{ID:1,称号:EVENT1,开始:2009-11-10 14时十八分15秒,结束: 2009-11-03 14点38分22秒,allDay:假,URL:空} {ID:2,称号:EVENT2,开始:2009年-11-09十五点41分二十秒,结束:2009-11-10 16点41分25秒,allDay:假,URL:空}
但我想要的结果看起来是这样的:
[{ID:1,称号:EVENT1,开始:2009-11-10十四点18分15秒,终结 2009-11-03 14时38分22秒,allDay:假,URL:空},{ID:2,称号:EVENT2,开始: 2009-11-09 15点41分二十〇秒,结束:2009-11-10 16点41分25秒,allDay:假,URL:空}]
我怎样才能做到这一点?
解决方案
$ ARR =阵列();
而($行= mysql_fetch_assoc($结果)){
$常用3 [] = $行;
}
回声json_en code($ ARR);
I have a problem using JSON and arrays.
Here is my code:
while($row = mysql_fetch_assoc($result)){ echo json_encode($row); }
The result is:
{"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}
But I want the result to look like this:
[{"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}]
How can I accomplish this?
解决方案
$arr = array();
while($row = mysql_fetch_assoc($result)) {
$arr[] = $row;
}
echo json_encode($arr);
这篇关于二维阵列上json_en code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!