陈情陈情
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) { ; }
厉害的
Java入门第二季 升级版
530553 学习 · 6091 问题
相似问题