第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

RestEntity Not Working 返回空的正文

RestEntity Not Working 返回空的正文

狐的傳說 2021-10-17 15:42:35
我使用 spring 2.0.5 Release 作為父級。我是春天的新手。我正在使用此 API https://www.metaweather.com/api/location/2487956/嘗試使用對象映射器顯示它,但我遇到了 RestTemplate 問題。public void read() throws IOException {     RestTemplate rest = new RestTemplate();     ResponseEntity<String> response  = rest.getForEntity("https://www.metaweather.com/api/location/2487956", String.class);     ObjectMapper mapper = new ObjectMapper();     JsonNode root = mapper.readTree(response.getBody());     JsonNode name = root.path("weather_state_name");     System.out.println(response.getBody());}
查看完整描述

1 回答

?
喵喔喔

TA貢獻1735條經(jīng)驗 獲得超5個贊

您的 RestEntity 很好,您沒有正確解析您的響應。weather_state_name 位于一個名為solidated_weather 的數(shù)組中。以下內容將滿足您的需求。


        ObjectMapper mapper = new ObjectMapper();

        JsonNode root = mapper.readTree(response.getBody());

        JsonNode consolidated_weather =root.get("consolidated_weather");

        consolidated_weather.forEach(x -> {


            System.out.println( x.get("weather_state_name"));

        });


查看完整回答
反對 回復 2021-10-17
  • 1 回答
  • 0 關注
  • 132 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號