hihelllo 大佬有话说 :
php如何生成这样的json格式呢?
{
"hello":100,
"data":[{
"id":1,
"title":"我是标题1",
"content":"我是内容1"
},{
"id":2,
"title":"我是标题2",
"content":"我是内容2"
},{
"id":3,
"title":"我是标题3",
"content":"我是内容3"
}]
}
完全不会这样的格式。。。
Mr. 大佬有话说 :
本帖最后由 Mr. 于 2020-5-10 23:52 编辑
<?php
$arr = [
"hello" => 100,
"data" => [
[
"id" => 1,
"title" => "我是标题1",
"content" => "我是内容1"
],
[
"id" => 2,
"title" => "我是标题2",
"content" => "我是内容2"
],
[
"id" => 3,
"title" => "我是标题3",
"content" => "我是内容3"
]
]
];
echo json_encode($arr);
camboo 大佬有话说 :
json看起来是后端的东西 不懂
JOSH 大佬有话说 :
多维数组 转json对象
https://cdn.jsdelivr.net/gh/hishis/forum-master/public/images/patch.gif
tir 大佬有话说 :
这不是josn嘛 哈哈
hihelllo 大佬有话说 :
Mr. 大佬有话说 : 2020-5-10 23:50
mysql_fetch_array查出数据
$a[]='{"id":’.$rows.’,"code":"’.$rows.’","type":"’.$rows.’"},’;
。。。。
$contentStr = implode(”,$a);
$myjson='{"hello":100,"data":[‘.$contentStr.’]}’;
header(‘content-type:application/json’);
echo str_replace(‘,]’,’]’,$myjson);
我现在是手动组合起来打印。。。哈哈:L
hihelllo 大佬有话说 :
JOSH 大佬有话说 : 2020-5-10 23:47
多维数组 转json对象
现在手动组合凑活用,str_replace替换掉最后一个, 哈哈