接口变了,复制我的这两个方法加进去就行了

来源:5-2 实现24小时天气预报查询功能

陈情陈情

2022-09-19 21:37

WeatherUtilsImpl WeatherUtils {
    <> getValue(Object map, String path, Class<> clazz) {
        {
            OgnlContext context = OgnlContext();
            context.setRoot(map);
            value = () Ognl.(path, context, context.getRoot());
            value;
        } (Exception e) {
            RuntimeException(e);
        }
    }

    List<HourWeather> w24h(String appCode, String area) {
        List<HourWeather> resultList = ArrayList<HourWeather>();
        {
            OkHttpClient client = OkHttpClient();
            Request request = Request.Builder()
                    .get()
                    .url(+ area)
                    .header(, + appCode)
                    .build();
            Call call = client.newCall(request);
            Response response = call.execute();
            Gson gson = GsonBuilder()
                    .setFieldNamingPolicy(FieldNamingPolicy.)
                    .create();
            String resBody = response.body().string();
            Map result = gson.fromJson(resBody, TypeToken<Map>() {
            }.getType());
            List<Map<String, String>> hourList = .getValue(result, , ArrayList.);
            (hourList == || hourList.size() == ) {
                ArrayList<HourWeather>();
            }
            (Map<String, String> hour : hourList) {
                HourWeather hourWeather = HourWeather();
                hourWeather.setYear(hour.get().substring(, ));
                hourWeather.setMonth(hour.get().substring(, ));
                hourWeather.setDay(hour.get().substring(, ));
                hourWeather.setHour(hour.get().substring(, ));
                hourWeather.setWindDirection(hour.get());
                hourWeather.setWindPower(hour.get());
                hourWeather.setWeather(hour.get());
                hourWeather.setTemperature(hour.get());
                resultList.add(hourWeather);
            }

        } (Exception e) {
            RuntimeException(e);
        }
        resultList;

    }

    List<DayWeather> w3d(String appCode, String area) {
        ;
    }

    List<DayWeather> w7d(String appCode, String area) {
        ;
    }


写回答 关注

1回答

  • 潮听哥
    2022-12-13 17:40:38

    厉害的

Java入门第二季 升级版

课程升级!以终为始告别枯燥,在开发和重构中体会Java面向对象编程的奥妙

530553 学习 · 6091 问题

查看课程

相似问题