本文介绍了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字符编码
发布评论