$result = ['code'=>0,'msg'=>'操作成功','data'=>[]
];
1,返回json数据汉字不转码
return response()->json($result)->setEncodingOptions(JSON_UNESCAPED_UNICODE);
返回空内容:
{
"code": "0",
"msg": "操作成功",
"data": []//未强制转为对象
}
返回列表数据:
{
"code": "0",
"msg": "操作成功",
"data": {
"0": {
"INFOCODE": "NW201905101118700113",
"SOURCE": "东方财富Choice数据",
"SHOWTIME": "2019-05-10 08:55",
"IMAGE": "http://pdf.dfcfw.com/pdf/H8_CJTP0022_1.jpg",
"TITLE": "航天科技:连续3日融资净买入累计1017万元(05-09)",
"DIGEST": null,
"sector_code": "650000",
"stats": {
"view_num": 0,
"like_num": 0,
"share_num": 0
}
},
"1": {
"INFOCODE": "NW201905101118620129",
"SOURCE": "东方财富Choice数据",
"SHOWTIME": "2019-05-10 07:54",
"IMAGE": "http://pdf.dfcfw.com/pdf/H8_CJTP0043_1.jpg",
"TITLE": "春秋航空:融资净买入125.27万元,融资余额3.64亿元(05-09)",
"DIGEST": null,
"sector_code": "650000",
"stats": {
"view_num": 0,
"like_num": 0,
"share_num": 0
}
}
}
}
2,返回json数据强制转换为对象
return response()->make(json_encode($result,JSON_FORCE_OBJECT|JSON_UNESCAPED_UNICODE),200,['Content-Type'=>'application/json']);
返回内容:
{
"code": "0",
"msg": "操作成功",
"data": {}//已强制转为对象
}
【laravel设置json返回编码和格式】返回列表数据:
{
"code": "0",
"msg": "操作成功",
"data": [
"0": {
"INFOCODE": "NW201905101118700113",
"SOURCE": "东方财富Choice数据",
"SHOWTIME": "2019-05-10 08:55",
"IMAGE": "http://pdf.dfcfw.com/pdf/H8_CJTP0022_1.jpg",
"TITLE": "航天科技:连续3日融资净买入累计1017万元(05-09)",
"DIGEST": null,
"sector_code": "650000",
"stats": {
"view_num": 0,
"like_num": 0,
"share_num": 0
}
},
"1": {
"INFOCODE": "NW201905101118620129",
"SOURCE": "东方财富Choice数据",
"SHOWTIME": "2019-05-10 07:54",
"IMAGE": "http://pdf.dfcfw.com/pdf/H8_CJTP0043_1.jpg",
"TITLE": "春秋航空:融资净买入125.27万元,融资余额3.64亿元(05-09)",
"DIGEST": null,
"sector_code": "650000",
"stats": {
"view_num": 0,
"like_num": 0,
"share_num": 0
}
}
]
}
推荐阅读
- laravel 8 修改默认的paginate分页模板
- laravel|国际支付对接,信用卡支付对接,stripe的使用
- laravel|laravel执行过程
- 搭建远程GIT
- Laravel 自带的Auth验证登录
- php|lnmp搭建遇到的尴尬事(一)
- Laravel mysql 添加外键失败
- php|laravel attempt登陆认证时候帐号密码输入正确但返回false的情况
- Laravel|laravel 验证大于零的数字
- laravel|Composer 本地路径加载 laravel-admin 扩展包