課程
/后端開發(fā)
/Java
/Java入門第二季 升級版
大佬們,這個(gè)報(bào)錯(cuò)原因是啥呀
2022-01-19
源自:Java入門第二季 升級版 5-4
正在回答
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(); ????????//獲取服務(wù)器返回?cái)?shù)據(jù) ????????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); ????????//如果沒有找到對應(yīng)地區(qū)天氣數(shù)據(jù),返回空的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; }
你下的那個(gè)阿里云里面的天氣預(yù)報(bào)的版本不一樣,要下跟老師一樣的那個(gè)版本,就是有免費(fèi)版三個(gè)字的版本
搜索
復(fù)制
舉報(bào)
課程升級!以終為始告別枯燥,在開發(fā)和重構(gòu)中體會Java面向?qū)ο缶幊痰膴W妙
3 回答大佬們,這個(gè)為啥會報(bào)錯(cuò)呀
5 回答主方法中創(chuàng)建內(nèi)部類報(bào)錯(cuò),啥原因求大佬
2 回答大佬們,為什么報(bào)錯(cuò)了呢
1 回答大佬們看看這個(gè)問題
1 回答大佬們指教一下
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2023-05-04
2022-08-11
你下的那個(gè)阿里云里面的天氣預(yù)報(bào)的版本不一樣,要下跟老師一樣的那個(gè)版本,就是有免費(fèi)版三個(gè)字的版本
搜索
復(fù)制