1.场景
1.1 我们后台给前端返回时数据的时候设置的返回格式的:MediaType.APPLICATION_JSON_UTF8_VALUE,希望前端(我们前端故事机是freertos系统)请求得到数据能直接得到中文。
见代码:
@RestController
@RequestMapping("/api/v4/page-manage")
public class ResourceFloorController extends BaseController {
@PostMapping(value = "/get-daily-fm", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Result getDailyFm(
Long pageId,
Long channelId,
String deviceId,
String sign,
String showField,
Integer pageNo,
Integer pageSize)
{
......(省掉的业务代码)
return ResultUtils.returnSuccess("请求成功!", object);
}
}
2.问题
2.1 故事机端(freertos系统)得到的响应数据:
HTTP/1.1 200
Server: nginx/1.16.1
Date: Thu, 27 Feb 2020 10:08:10 GMT
Content-Type: application/json;charset=UTF-8
Content-Length: 248
Connection: keep-alive
{"code":1,"data":{"allField":"id,name,url,coverImage","name":"\u4F60\u7B11\u8D77\u6765\u771F\u597D\u770B","id":43888,"url":"https:\/\/2.zoppoz.workers.dev:443\/http\/118.178.000.0\/hht_file\/cloud\/\/TiRtEDJY10697_1582103141.mp3"},"info":"\u8BF7\u6C42\u6210\u529F!","success":true}
2.2 我自己用curl请求数据发现得到的数据编码的unicode格式的。见图:
这里我在接口处指定了数据的返回格式和编码格式:application/json;charset=UTF-8,但是前端接收到的还是unicode编码的数据。
3.解决方法(自己不知道原因,求大佬耐心解答)
1.1 服务器接口端@PostMapping的produces值设置成:"application/problem+json;charset=UTF-8"就正常了。正常返回数据:
请教大佬!!!