resttemplate乱码
解决方案:
参考:Spring RestTemplate 调用天气预报接口乱码的解决
一:
RestTemplate restTemplate = new RestTemplate(
new HttpComponentsClientHttpRequestFactory()); // 使用HttpClient,支持GZIP
restTemplate.getMessageConverters().set(1,
new StringHttpMessageConverter(StandardCharsets.UTF_8)); // 支持中文编码
String body = restTemplate.getForObject("https://devapi.qweather.com/v7/weather/3d?location=101010100&key=7f39185f15344739b9304168b55ce56c", String.class);
二:
maven 依赖
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.12.1</version>
</dependency>
Connection.Response execute = Jsoup.connect("https://devapi.qweather.com/v7/weather/3d?location=101010100&key=7f39185f15344739b9304168b55ce56c").ignoreContentType(true).execute();
JSONObject jsonObject = JSONObject.parseObject(execute.body());
System.out.println(jsonObject.getString("code"));