欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

怎么将多个json组合成一个

程序员文章站 2022-05-24 11:56:08
...
如何将多个json组合成一个?
本帖最后由 sigkl00181 于 2015-04-22 14:15:39 编辑

$question = $_GET['question'];
$arr = explode("|",$question);
for($i = 0;$i $rid = $arr[$i];
$sql = "select * from xs_radio where rid = '$rid'";
$result = mysql_query($sql);
$arr = array();
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$ar[] = $row;
}
$js = json_encode($ar);
echo $js;
}

这是查询的语句

[{"rid":"1","title":"\u6211\u662f\u8c01","a":"\u5b8b\u5411\u4e1c","b":"\u9b4f\u4eae","c":"\u738b\u514b\u5a07","d":"\u5b8b\u5b50\u6587","answer":"\u5b8b\u5411\u4e1c"}]
[{"rid":"2","title":"\u6211\u662f\u8c01","a":"\u9b4f\u4eae","b":"\u5218\u5fb7\u534e","c":"\u674e\u5a1c","d":"\u5f20\u626c","answer":"\u9b4f\u4eae"}]
[{"rid":"3","title":"\u6211\u662f\u8c01","a":"\u9b4f\u4eae","b":"\u738b\u514b\u5a07","c":"\u674e\u56fd\u4f1f","d":"\u738b\u83f2","answer":"\u738b\u514b\u5a07"}]
[{"rid":"16","title":"\u6211\u662f\u8c01","a":"\u5218\u5f66\u5bbe","b":"\u674e\u56fd\u632f","c":"\u7a0b\u79c0\u82b9","d":"\u738b\u514b\u5a07","answer":"\u738b\u514b\u5a07"}]

查询出来的结果。 如何把这三个json组合成一个?

[{"rid":"1","title":"\u6211\u662f\u8c01","a":"\u5b8b\u5411\u4e1c","b":"\u9b4f\u4eae","c":"\u738b\u514b\u5a07","d":"\u5b8b\u5b50\u6587","answer":"\u5b8b\u5411\u4e1c"},
{"rid":"2","title":"\u6211\u662f\u8c01","a":"\u9b4f\u4eae","b":"\u5218\u5fb7\u534e","c":"\u674e\u5a1c","d":"\u5f20\u626c","answer":"\u9b4f\u4eae"},
{"rid":"3","title":"\u6211\u662f\u8c01","a":"\u9b4f\u4eae","b":"\u738b\u514b\u5a07","c":"\u674e\u56fd\u4f1f","d":"\u738b\u83f2","answer":"\u738b\u514b\u5a07"},
{"rid":"16","title":"\u6211\u662f\u8c01","a":"\u5218\u5f66\u5bbe","b":"\u674e\u56fd\u632f","c":"\u7a0b\u79c0\u82b9","d":"\u738b\u514b\u5a07","answer":"\u738b\u514b\u5a07"}]

保存成这样的。
------解决思路----------------------
转数组 然后合成一个数组 再转json
------解决思路----------------------
把 $ar[] = $row;
改为 $ar[$i][] = $row;


$js = json_encode($ar);
echo $js;
移到 for 循环后面
怎么将多个json组合成一个

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频


网友评论

文明上网理性发言,请遵守 新闻评论服务协议

我要评论
  • 怎么将多个json组合成一个
  • 专题推荐