Springboot 发起http请求调用高德接口

RestTemplate templates = new RestTemplate();

  //高德天气状况请求地址
        String url = "https://restapi.amap.com/v3/weather/weatherInfo?key="+GaoDekey+"&city="+code;

        //  发起HTTP请求 获取高德天气状况
        RestTemplate templates = new RestTemplate();
        ResponseEntity<String> getWeather = templates.getForEntity(url, String.class);
        String weather = getWeather.getBody();


        //json 数据转化为 实体类
        GaodeInfor bean = JSONObject.parseObject(weather, GaodeInfor.class);
        String weatherinfo = bean.getLives().toString();
        String   weatherinforp= weatherinfo.replace("[","").replace("]","");
        Weather weathers = JSONObject.parseObject(weatherinforp, Weather.class);
发布了78 篇原创文章 · 获赞 5 · 访问量 7370

猜你喜欢

转载自blog.csdn.net/weixin_41930050/article/details/103149924
今日推荐