大佬们,这个报错原因是啥呀
大佬们,这个报错原因是啥呀
大佬们,这个报错原因是啥呀
2022-01-19
public List<DayWeather> w3d(String appCode, String area) { List<DayWeather> resultList = new ArrayList<DayWeather>(); try { //新建查询请求 OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .get() .url("http://ali-weather.showapi.com/day15?area=" + area) .header("Authorization", "APPCODE " + appCode) .build(); Call call = client.newCall(request); Response response = call.execute(); Gson gson = new GsonBuilder() .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .create(); //获取服务器返回数据 String resBody = response.body().string(); Map result = gson.fromJson(resBody, new TypeToken<Map>() { }.getType()); //包装为对象集合 // ************* 以下是修改部分 ******************** List<Map<String, String>> dayList = this.getValue(result, "showapi_res_body.dayList", ArrayList.class); //如果没有找到对应地区天气数据,返回空的List列表 if (dayList == null || dayList.size() == 0) { return new ArrayList<DayWeather>(); } Iterator<Map<String, String>> iterator = dayList.iterator(); for (int i = 0; i < 3; i++) { if (iterator.hasNext()) { Map<String, String> day = iterator.next(); DayWeather dayWeather = new DayWeather(); dayWeather.setYear(day.get("daytime").substring(0, 4)); dayWeather.setMonth(day.get("daytime").substring(4, 6)); dayWeather.setDay(day.get("daytime").substring(6, 8)); dayWeather.setDayAirTemperature(day.get("day_air_temperature")); dayWeather.setNightAirTemperature(day.get("night_air_temperature")); dayWeather.setDayWeather(day.get("day_weather")); dayWeather.setNightWeather(day.get("night_weather")); dayWeather.setDayWindPower(day.get("day_wind_power")); dayWeather.setNightWindPower(day.get("night_wind_power")); resultList.add(dayWeather); } } // ************* 以上是修改部分 ******************** } catch (Exception e) { throw new RuntimeException(e); } return resultList; }
举报