laravel设置json返回编码和格式

$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 } } ] }

    推荐阅读