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);

你可能感兴趣的:(Springboot)