Java Spring resttemplate字符编码

编程入门 行业动态 更新时间:2024-10-26 12:32:20
本文介绍了Java Spring resttemplate字符编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用Java Spring Resttemplate通过get请求获取json。我得到的JSON而不是特殊字符slikeüöä或ß一些奇怪的东西。所以我想有些字符编码的错误。我在互联网上找不到任何帮助。我现在使用的代码是:

I'm using the Java Spring Resttemplate for getting a json via a get request. The JSON I'm getting has instead of special character slike ü ö ä or ß some weird stuff. So I guess somethings wrong with the character encoding. I can't find any help on the internet. The code I'm using for now is:

String json = restTemplate.getForObject( overPassStatementPostCode, String.class, params);

推荐答案

您只需要添加 StringHttpMessageConverter 到模板的消息转换器:

You just need to add the StringHttpMessageConverter to the template's message converters:

RestTemplate template = new RestTemplate(); template.getMessageConverters() .add(0, new StringHttpMessageConverter(Charset.forName("UTF-8"))); ResponseEntity<Object> response = template.exchange(endpoint, method, entity, Object.class);

更多推荐

Java Spring resttemplate字符编码

本文发布于:2023-10-11 13:49:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1481875.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符   Java   Spring   resttemplate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!