編輯:關於Android編程
學習了好久的安卓,把各個組件基本都學完了,就想自己做個軟件鞏固一下學習的知識,順便體驗一下做項目的感覺,好了,廢話不多說,下面開始進行軟件的制作。
首先,要做天氣軟件,當然需要獲取天氣數據了,我用的是百度的API,這裡順便附上鏈接百度天氣api,我下載的是SDK,這樣就簡化了許多。具體SDK的使用方法,下載的壓縮包裡面有,這裡就不再贅述了,如果不會的話可以留言。
這裡的獲取的天氣數據都是json形式,所以要進行json數據解析,你可以直接選擇json解析,也可以使用gson和fastgson進行解析發,這裡我使用的是直接json解析。
我們現在來看一下,從服務器返回的json數據。
{“HeWeather data service 3.0”:[{“aqi”:{“city”:{“aqi”:”82”,”pm10”:”83”,”pm25”:”60”}},”basic”:{“city”:”安陽”,”cnty”:”中國”,”id”:”CN101180201”,”lat”:”36.093000”,”lon”:”114.341000”,”update”:{“loc”:”2016-05-14 20:51”,”utc”:”2016-05-14 12:51”}},”daily_forecast”:[{“astro”:{“sr”:”05:17”,”ss”:”19:20”},”cond”:{“code_d”:”306”,”code_n”:”305”,”txt_d”:”中雨”,”txt_n”:”小雨”},”date”:”2016-05-14”,”hum”:”88”,”pcpn”:”18.0”,”pop”:”98”,”pres”:”1018”,”tmp”:{“max”:”16”,”min”:”11”},”vis”:”7”,”wind”:{“deg”:”15”,”dir”:”西北風”,”sc”:”微風”,”spd”:”2”}},{“astro”:{“sr”:”05:16”,”ss”:”19:21”},”cond”:{“code_d”:”100”,”code_n”:”100”,”txt_d”:”晴”,”txt_n”:”晴”},”date”:”2016-05-15”,”hum”:”13”,”pcpn”:”0.0”,”pop”:”0”,”pres”:”1018”,”tmp”:{“max”:”24”,”min”:”11”},”vis”:”10”,”wind”:{“deg”:”15”,”dir”:”西南風”,”sc”:”微風”,”spd”:”0”}},{“astro”:{“sr”:”05:15”,”ss”:”19:22”},”cond”:{“code_d”:”100”,”code_n”:”100”,”txt_d”:”晴”,”txt_n”:”晴”},”date”:”2016-05-16”,”hum”:”13”,”pcpn”:”0.0”,”pop”:”0”,”pres”:”1013”,”tmp”:{“max”:”29”,”min”:”13”},”vis”:”10”,”wind”:{“deg”:”194”,”dir”:”南風”,”sc”:”微風”,”spd”:”7”}},{“astro”:{“sr”:”05:14”,”ss”:”19:23”},”cond”:{“code_d”:”100”,”code_n”:”101”,”txt_d”:”晴”,”txt_n”:”多雲”},”date”:”2016-05-17”,”hum”:”19”,”pcpn”:”0.0”,”pop”:”0”,”pres”:”1009”,”tmp”:{“max”:”29”,”min”:”16”},”vis”:”10”,”wind”:{“deg”:”195”,”dir”:”南風”,”sc”:”微風”,”spd”:”4”}},{“astro”:{“sr”:”05:14”,”ss”:”19:24”},”cond”:{“code_d”:”101”,”code_n”:”101”,”txt_d”:”多雲”,”txt_n”:”多雲”},”date”:”2016-05-18”,”hum”:”24”,”pcpn”:”0.0”,”pop”:”0”,”pres”:”1012”,”tmp”:{“max”:”27”,”min”:”15”},”vis”:”10”,”wind”:{“deg”:”165”,”dir”:”東南風”,”sc”:”微風”,”spd”:”6”}},{“astro”:{“sr”:”05:13”,”ss”:”19:24”},”cond”:{“code_d”:”101”,”code_n”:”305”,”txt_d”:”多雲”,”txt_n”:”小雨”},”date”:”2016-05-19”,”hum”:”19”,”pcpn”:”0.0”,”pop”:”0”,”pres”:”1015”,”tmp”:{“max”:”27”,”min”:”16”},”vis”:”10”,”wind”:{“deg”:”126”,”dir”:”無持續風向”,”sc”:”微風”,”spd”:”5”}},{“astro”:{“sr”:”05:12”,”ss”:”19:25”},”cond”:{“code_d”:”305”,”code_n”:”101”,”txt_d”:”小雨”,”txt_n”:”多雲”},”date”:”2016-05-20”,”hum”:”15”,”pcpn”:”0.0”,”pop”:”0”,”pres”:”1019”,”tmp”:{“max”:”23”,”min”:”16”},”vis”:”10”,”wind”:{“deg”:”99”,”dir”:”無持續風向”,”sc”:”微風”,”spd”:”5”}}],”hourly_forecast”:[{“date”:”2016-05-14 22:00”,”hum”:”91”,”pop”:”93”,”pres”:”1018”,”tmp”:”14”,”wind”:{“deg”:”264”,”dir”:”西風”,”sc”:”微風”,”spd”:”5”}}],”now”:{“cond”:{“code”:”300”,”txt”:”陣雨”},”fl”:”15”,”hum”:”88”,”pcpn”:”.2”,”pres”:”1018”,”tmp”:”13”,”vis”:”7”,”wind”:{“deg”:”343”,”dir”:”西南風”,”sc”:”4-5”,”spd”:”19”}},”status”:”ok”,”suggestion”:{“comf”:{“brf”:”舒適”,”txt”:”白天不太熱也不太冷,風力不大,相信您在這樣的天氣條件下,應會感到比較清爽和舒適。”},”cw”:{“brf”:”不宜”,”txt”:”不宜洗車,未來24小時內有雨,如果在此期間洗車,雨水和路上的泥水可能會再次弄髒您的愛車。”},”drsg”:{“brf”:”舒適”,”txt”:”建議著長袖T恤、襯衫加單褲等服裝。年老體弱者宜著針織長袖襯衫、馬甲和長褲。”},”flu”:{“brf”:”較易發”,”txt”:”晝夜溫差較大,較易發生感冒,請適當增減衣服。體質較弱的朋友請注意防護。”},”sport”:{“brf”:”較適宜”,”txt”:”天氣較好,但風力較大,推薦您進行室內運動,若在戶外運動請注意防風。”},”trav”:{“brf”:”適宜”,”txt”:”天氣較好,風稍大,但溫度適宜,是個好天氣哦。適宜旅游,您可以盡情地享受大自然的無限風光。”},”uv”:{“brf”:”中等”,”txt”:”屬中等強度紫外線輻射天氣,外出時建議塗擦SPF高於15、PA+的防曬護膚品,戴帽子、太陽鏡。”}}},{“basic”:{“city”:”Anyang”,”cnty”:”Korea”,”id”:”KR1846898”,”lat”:”37.392502”,”lon”:”126.926941”,”update”:{“loc”:”2016-05-14 21:00”,”utc”:”2016-05-14 12:00”}},”daily_forecast”:[{“astro”:{“sr”:”05:24”,”ss”:”19:34”},”cond”:{“code_d”:”100”,”code_n”:”103”,”txt_d”:”Sunny/Clear”,”txt_n”:”Partly Cloudy”},”date”:”2016-05-14”,”hum”:”54”,”pcpn”:”0.0”,”pop”:”0”,”pres”:”1025”,”tmp”:{“max”:”23”,”min”:”14”},”vis”:”10”,”wind”:{“deg”:”127”,”dir”:”SE”,”sc”:”1-2”,”spd”:”13”}},{“astro”:{“sr”:”05:24”,”ss”:”19:35”},”cond”:{“code_d”:”100”,”code_n”:”306”,”txt_d”:”Sunny/Clear”,”txt_n”:”Moderate Rain”},”date”:”2016-05-15”,”hum”:”68”,”pcpn”:”23.5”,”pop”:”88”,”pres”:”1016”,”tmp”:{“max”:”22”,”min”:”11”},”vis”:”10”,”wind”:{“deg”:”134”,”dir”:”SE”,”sc”:”1-2”,”spd”:”13”}},{“astro”:{“sr”:”05:23”,”ss”:”19:36”},”cond”:{“code_d”:”100”,”code_n”:”100”,”txt_d”:”Sunny/Clear”,”txt_n”:”Sunny/Clear”},”date”:”2016-05-16”,”hum”:”69”,”pcpn”:”8.9”,”pop”:”84”,”pres”:”1008”,”tmp”:{“max”:”20”,”min”:”16”},”vis”:”10”,”wind”:{“deg”:”325”,”dir”:”NW”,”sc”:”1-2”,”spd”:”13”}},{“astro”:{“sr”:”05:22”,”ss”:”19:36”},”cond”:{“code_d”:”100”,”code_n”:”100”,”txt_d”:”Sunny/Clear”,”txt_n”:”Sunny/Clear”},”date”:”2016-05-17”,”hum”:”57”,”pcpn”:”0.0”,”pop”:”0”,”pres”:”1016”,”tmp”:{“max”:”24”,”min”:”13”},”vis”:”10”,”wind”:{“deg”:”190”,”dir”:”S”,”sc”:”1-2”,”spd”:”13”}},{“astro”:{“sr”:”05:21”,”ss”:”19:37”},”cond”:{“code_d”:”100”,”code_n”:”103”,”txt_d”:”Sunny/Clear”,”txt_n”:”Partly Cloudy”},”date”:”2016-05-18”,”hum”:”50”,”pcpn”:”0.0”,”pop”:”0”,”pres”:”1019”,”tmp”:{“max”:”26”,”min”:”16”},”vis”:”10”,”wind”:{“deg”:”1”,”dir”:”N”,”sc”:”1-2”,”spd”:”13”}},{“astro”:{“sr”:”05:20”,”ss”:”19:38”},”cond”:{“code_d”:”103”,”code_n”:”100”,”txt_d”:”Partly Cloudy”,”txt_n”:”Sunny/Clear”},”date”:”2016-05-19”,”hum”:”57”,”pcpn”:”0.0”,”pop”:”0”,”pres”:”1021”,”tmp”:{“max”:”30”,”min”:”21”},”vis”:”10”,”wind”:{“deg”:”55”,”dir”:”NE”,”sc”:”1-2”,”spd”:”13”}},{“astro”:{“sr”:”05:20”,”ss”:”19:39”},”cond”:{“code_d”:”100”,”code_n”:”100”,”txt_d”:”Sunny/Clear”,”txt_n”:”Sunny/Clear”},”date”:”2016-05-20”,”hum”:”52”,”pcpn”:”0.0”,”pop”:”0”,”pres”:”1022”,”tmp”:{“max”:”31”,”min”:”21”},”vis”:”10”,”wind”:{“deg”:”34”,”dir”:”NE”,”sc”:”1-2”,”spd”:”13”}}],”hourly_forecast”:[{“date”:”2016-05-14 22:00”,”hum”:”76”,”pop”:”0”,”pres”:”1021”,”tmp”:”15”,”wind”:{“deg”:”264”,”dir”:”W”,”sc”:”1-2”,”spd”:”4”}}],”now”:{“cond”:{“code”:”103”,”txt”:”Partly Cloudy”},”fl”:”24”,”hum”:”46”,”pcpn”:”0.0”,”pres”:”1018”,”tmp”:”22”,”vis”:”10”,”wind”:{“deg”:”300”,”dir”:”WNW”,”sc”:”1-2”,”spd”:”13”}},”status”:”ok”}]}
是不是感覺特別復雜,所以呢你要是進行全部解析,還是推薦你用gson或fastgson的方式進行解析。Android studio裡面有gson插件,使用起來也比較方便,不過要注意像這種“HeWeather data service 3.0” 一定要沒有空格才能利用Android studio中的gson插件生成實體類,不然就會提示解析錯誤。
這裡我只解析我要用到的數據,既然要解析,肯定需要一個實體類了,我定義的實體類內容如下:
package com.baidu.apistore.sdk.bena;
import java.util.List;
/**
* Created by xiaohui on 2016/5/15.
*/
public class WeatherBean {
private List mOneDayWeatherInfs;
private int now;
private int aqi;
private int pm10;
private int pm25;
private String city;
private String cond_txt;
private String cnty;
private String comfBrf;
private String comfTxt;
private String cwBrf;
private String cwTxt;
private String drsgBrf;
private String drsgTxt;
private String fluBrf;
private String fluTxt;
private String sportBrf;
private String sportTxt;
private String travBrf;
private String travTxt;
private String uvBrf;
private String uvTxt;
public WeatherBean() {
}
public WeatherBean(int aqi, String city, String cnty, String comfBrf, String comfTxt, String cond_txt, String cwBrf, String cwTxt, String drsgBrf, String drsgTxt, String fluBrf, String fluTxt, List oneDayWeatherInfs, int now, int pm10, int pm25, String sportBrf, String sportTxt, String travBrf, String travTxt, String uvBrf, String uvTxt) {
this.aqi = aqi;
this.city = city;
this.cnty = cnty;
this.comfBrf = comfBrf;
this.comfTxt = comfTxt;
this.cond_txt = cond_txt;
this.cwBrf = cwBrf;
this.cwTxt = cwTxt;
this.drsgBrf = drsgBrf;
this.drsgTxt = drsgTxt;
this.fluBrf = fluBrf;
this.fluTxt = fluTxt;
mOneDayWeatherInfs = oneDayWeatherInfs;
this.now = now;
this.pm10 = pm10;
this.pm25 = pm25;
this.sportBrf = sportBrf;
this.sportTxt = sportTxt;
this.travBrf = travBrf;
this.travTxt = travTxt;
this.uvBrf = uvBrf;
this.uvTxt = uvTxt;
}
public int getAqi() {
return aqi;
}
public void setAqi(int aqi) {
this.aqi = aqi;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCnty() {
return cnty;
}
public void setCnty(String cnty) {
this.cnty = cnty;
}
public String getComfBrf() {
return comfBrf;
}
public void setComfBrf(String comfBrf) {
this.comfBrf = comfBrf;
}
public String getComfTxt() {
return comfTxt;
}
public void setComfTxt(String comfTxt) {
this.comfTxt = comfTxt;
}
public String getCond_txt() {
return cond_txt;
}
public void setCond_txt(String cond_txt) {
this.cond_txt = cond_txt;
}
public String getCwBrf() {
return cwBrf;
}
public void setCwBrf(String cwBrf) {
this.cwBrf = cwBrf;
}
public String getCwTxt() {
return cwTxt;
}
public void setCwTxt(String cwTxt) {
this.cwTxt = cwTxt;
}
public String getDrsgBrf() {
return drsgBrf;
}
public void setDrsgBrf(String drsgBrf) {
this.drsgBrf = drsgBrf;
}
public String getDrsgTxt() {
return drsgTxt;
}
public void setDrsgTxt(String drsgTxt) {
this.drsgTxt = drsgTxt;
}
public String getFluBrf() {
return fluBrf;
}
public void setFluBrf(String fluBrf) {
this.fluBrf = fluBrf;
}
public String getFluTxt() {
return fluTxt;
}
public void setFluTxt(String fluTxt) {
this.fluTxt = fluTxt;
}
public List getOneDayWeatherInfs() {
return mOneDayWeatherInfs;
}
public void setOneDayWeatherInfs(List oneDayWeatherInfs) {
mOneDayWeatherInfs = oneDayWeatherInfs;
}
public int getNow() {
return now;
}
public void setNow(int now) {
this.now = now;
}
public int getPm10() {
return pm10;
}
public void setPm10(int pm10) {
this.pm10 = pm10;
}
public int getPm25() {
return pm25;
}
public void setPm25(int pm25) {
this.pm25 = pm25;
}
public String getSportBrf() {
return sportBrf;
}
public void setSportBrf(String sportBrf) {
this.sportBrf = sportBrf;
}
public String getSportTxt() {
return sportTxt;
}
public void setSportTxt(String sportTxt) {
this.sportTxt = sportTxt;
}
public String getTravBrf() {
return travBrf;
}
public void setTravBrf(String travBrf) {
this.travBrf = travBrf;
}
public String getTravTxt() {
return travTxt;
}
public void setTravTxt(String travTxt) {
this.travTxt = travTxt;
}
public String getUvBrf() {
return uvBrf;
}
public void setUvBrf(String uvBrf) {
this.uvBrf = uvBrf;
}
public String getUvTxt() {
return uvTxt;
}
public void setUvTxt(String uvTxt) {
this.uvTxt = uvTxt;
}
@Override
public String toString() {
return "WeatherBean{" +
"aqi=" + aqi +
", mOneDayWeatherInfs=" + mOneDayWeatherInfs +
", now=" + now +
", pm10=" + pm10 +
", pm25=" + pm25 +
", city='" + city + '\'' +
", cond_txt='" + cond_txt + '\'' +
", cnty='" + cnty + '\'' +
", comfBrf='" + comfBrf + '\'' +
", comfTxt='" + comfTxt + '\'' +
", cwBrf='" + cwBrf + '\'' +
", cwTxt='" + cwTxt + '\'' +
", drsgBrf='" + drsgBrf + '\'' +
", drsgTxt='" + drsgTxt + '\'' +
", fluBrf='" + fluBrf + '\'' +
", fluTxt='" + fluTxt + '\'' +
", sportBrf='" + sportBrf + '\'' +
", sportTxt='" + sportTxt + '\'' +
", travBrf='" + travBrf + '\'' +
", travTxt='" + travTxt + '\'' +
", uvBrf='" + uvBrf + '\'' +
", uvTxt='" + uvTxt + '\'' +
'}';
}
}
我們會發現裡面List 的泛型是OneDayWeatherInfs,所以還需要一個OneDayWeatherInfs 類,其內容如下:
package com.baidu.apistore.sdk.bena;
/**
* Created by xiaohui on 2016/5/15.
*/
public class OneDayWeatherInfs {
private String condD;
private String condN;
private String date;
private String windDir;
private String windSc;
private String windSpd;
private int tmpMax;
private int tmpMin;
public OneDayWeatherInfs() {
}
public OneDayWeatherInfs(String condD, String condN, String date, int tmpMax, int tmpMin, String windDir, String windSc, String windSpd) {
this.condD = condD;
this.condN = condN;
this.date = date;
this.tmpMax = tmpMax;
this.tmpMin = tmpMin;
this.windDir = windDir;
this.windSc = windSc;
this.windSpd = windSpd;
}
public String getCondD() {
return condD;
}
public void setCondD(String condD) {
this.condD = condD;
}
public String getCondN() {
return condN;
}
public void setCondN(String condN) {
this.condN = condN;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public int getTmpMax() {
return tmpMax;
}
public void setTmpMax(int tmpMax) {
this.tmpMax = tmpMax;
}
public int getTmpMin() {
return tmpMin;
}
public void setTmpMin(int tmpMin) {
this.tmpMin = tmpMin;
}
public String getWindDir() {
return windDir;
}
public void setWindDir(String windDir) {
this.windDir = windDir;
}
public String getWindSc() {
return windSc;
}
public void setWindSc(String windSc) {
this.windSc = windSc;
}
public String getWindSpd() {
return windSpd;
}
public void setWindSpd(String windSpd) {
this.windSpd = windSpd;
}
@Override
public String toString() {
return "OneDayWeatherInfs{" +
"condD='" + condD + '\'' +
", condN='" + condN + '\'' +
", date='" + date + '\'' +
", windDir='" + windDir + '\'' +
", windSc='" + windSc + '\'' +
", windSpd='" + windSpd + '\'' +
", tmpMax=" + tmpMax +
", tmpMin=" + tmpMin +
'}';
}
}
好了實體類已經寫好,下面就要進行json解析了,解析json的類如下:
package com.baidu.apistore.sdk.prase;
import com.baidu.apistore.sdk.bena.OneDayWeatherInfs;
import com.baidu.apistore.sdk.bena.WeatherBean;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
* Created by xiaohui on 2016/5/15.
*/
public class Parse {
public Parse() {
}
public static WeatherBean resolveWeatherInf(String strPar) {
WeatherBean weatherBean = new WeatherBean();
try {
JSONObject dataOfJson = new JSONObject(strPar);
JSONArray jsonArray = dataOfJson.getJSONArray("HeWeather data service 3.0");
//空氣質量解析
JSONObject jsonArray0 = jsonArray.getJSONObject(0);
JSONObject aqi = jsonArray0.getJSONObject("aqi");
JSONObject city = aqi.getJSONObject("city");
weatherBean.setAqi(city.getInt("aqi"));
weatherBean.setPm10(city.getInt("pm10"));
weatherBean.setPm25(city.getInt("pm25"));
JSONObject basic = jsonArray0.getJSONObject("basic");
weatherBean.setCity(basic.getString("city"));
weatherBean.setCnty(basic.getString("cnty"));
//當前溫度
JSONObject now = jsonArray0.getJSONObject("now");
JSONObject nowCond = now.getJSONObject("cond");
weatherBean.setNow(now.getInt("tmp"));
weatherBean.setCond_txt(nowCond.getString("txt"));
//連續七天的天氣數據解析
List list = new ArrayList<>();
JSONArray daily_forecast = jsonArray0.getJSONArray("daily_forecast");
for (int i = 0; i < 7; i++) {
OneDayWeatherInfs oneDayWeatherInfs = new OneDayWeatherInfs();
JSONObject oneDayWeather = daily_forecast.getJSONObject(i);
JSONObject cond = oneDayWeather.getJSONObject("cond");
JSONObject temp = oneDayWeather.getJSONObject("tmp");
JSONObject wind = oneDayWeather.getJSONObject("wind");
oneDayWeatherInfs.setWindDir(wind.getString("dir"));
oneDayWeatherInfs.setWindSc(wind.getString("sc"));
oneDayWeatherInfs.setWindSpd(wind.getString("spd"));
oneDayWeatherInfs.setTmpMax(temp.getInt("max"));
oneDayWeatherInfs.setTmpMin(temp.getInt("min"));
oneDayWeatherInfs.setCondD(cond.getString("txt_d"));
oneDayWeatherInfs.setCondN(cond.getString("txt_n"));
oneDayWeatherInfs.setDate(oneDayWeather.getString("date"));
list.add(oneDayWeatherInfs);
}
weatherBean.setOneDayWeatherInfs(list);
//舒適度指數解析
JSONObject suggesttion = jsonArray0.getJSONObject("suggestion");
JSONObject comf = suggesttion.getJSONObject("comf");
weatherBean.setComfBrf(comf.getString("brf"));
weatherBean.setComfTxt(comf.getString("txt"));
JSONObject cw = suggesttion.getJSONObject("cw");
weatherBean.setCwBrf(cw.getString("brf"));
weatherBean.setCwTxt(cw.getString("txt"));
JSONObject drsg = suggesttion.getJSONObject("drsg");
weatherBean.setDrsgBrf(drsg.getString("brf"));
weatherBean.setDrsgTxt(drsg.getString("txt"));
JSONObject flu = suggesttion.getJSONObject("flu");
weatherBean.setFluBrf(flu.getString("brf"));
weatherBean.setFluTxt(flu.getString("txt"));
JSONObject sport = suggesttion.getJSONObject("sport");
weatherBean.setSportBrf(sport.getString("brf"));
weatherBean.setSportTxt(sport.getString("txt"));
JSONObject trav = suggesttion.getJSONObject("trav");
weatherBean.setTravBrf(trav.getString("brf"));
weatherBean.setTravTxt(trav.getString("txt"));
JSONObject uv = suggesttion.getJSONObject("uv");
weatherBean.setUvBrf(uv.getString("brf"));
weatherBean.setUvTxt(uv.getString("txt"));
} catch (JSONException e) {
e.printStackTrace();
}
return weatherBean;
}
}
上面就是進行json數據解析的類,然後就是解析服務器返回來的數據了,具體內容如下:
/**
* 這裡的apiTest()方法是百度SDK自帶的,返回的是json數據,
* 我們只要在onSuccess方法裡面添加解析json數據的方法就好了。
*/
private void apiTest() {
final Parameters para = new Parameters();
para.put("city", "安陽");
ApiStoreSDK.execute("http://apis.baidu.com/heweather/weather/free",
ApiStoreSDK.GET,
para,
new ApiCallBack() {
@Override
public void onSuccess(int status, String responseString) {
Log.i("sdkdemo", "onSuccess");
Log.i("sdkdemo", "responseString" + responseString);
WeatherBean weatherBean = null;
Parse parse = new Parse();
weatherBean = parse.resolveWeatherInf(responseString);
}
@Override
public void onComplete() {
Log.i("sdkdemo", "onComplete");
}
@Override
public void onError(int status, String responseString, Exception e) {
Log.i("sdkdemo", "onError, status: " + status);
Log.i("sdkdemo", "errMsg: " + (e == null ? "" : e.getMessage()));
Toast.makeText(MainActivity.this, "" + getStackTrace(e), Toast.LENGTH_SHORT).show();
}
});
}
解析出來的數據如下:
05-25 20:10:02.121 5162-5162/com.baidu.apistore.sdk I/fnhFire: weatherBean—>WeatherBean{aqi=51, mOneDayWeatherInfs=[OneDayWeatherInfs{condD=’晴’, condN=’陰’, date=’2016-05-25’, windDir=’西北風’, windSc=’3-4’, windSpd=’16’, tmpMax=33, tmpMin=18}, OneDayWeatherInfs{condD=’多雲’, condN=’多雲’, date=’2016-05-26’, windDir=’南風’, windSc=’微風’, windSpd=’2’, tmpMax=29, tmpMin=18}, OneDayWeatherInfs{condD=’小雨’, condN=’小雨’, date=’2016-05-27’, windDir=’南風’, windSc=’微風’, windSpd=’10’, tmpMax=23, tmpMin=15}, OneDayWeatherInfs{condD=’多雲’, condN=’多雲’, date=’2016-05-28’, windDir=’南風’, windSc=’微風’, windSpd=’8’, tmpMax=29, tmpMin=17}, OneDayWeatherInfs{condD=’多雲’, condN=’多雲’, date=’2016-05-29’, windDir=’東北風’, windSc=’微風’, windSpd=’7’, tmpMax=32, tmpMin=19}, OneDayWeatherInfs{condD=’多雲’, condN=’陰’, date=’2016-05-30’, windDir=’無持續風向’, windSc=’微風’, windSpd=’7’, tmpMax=33, tmpMin=20}, OneDayWeatherInfs{condD=’小雨’, condN=’小雨’, date=’2016-05-31’, windDir=’無持續風向’, windSc=’微風’, windSpd=’5’, tmpMax=29, tmpMin=20}], now=23, pm10=50, pm25=11, city=’安陽’, cond_txt=’多雲’, cnty=’中國’, comfBrf=’暫缺’, comfTxt=’暫缺’, cwBrf=’較適宜’, cwTxt=’較適宜洗車,未來一天無雨,風力較小,擦洗一新的汽車至少能保持一天。’, drsgBrf=’暫缺’, drsgTxt=’暫缺’, fluBrf=’暫缺’, fluTxt=’暫缺’, sportBrf=’暫缺’, sportTxt=’暫缺’, travBrf=’暫缺’, travTxt=’暫缺’, uvBrf=’暫缺’, uvTxt=’暫缺’}
額(⊙o⊙)…,也不知道怎麼回事,在寫這篇博客的時候,上面的好多數據都出現了暫缺,我能保證在這以前肯定是可以的。就先這樣吧,應該是百度API發神經了,好了,到這裡我們的json數據解析方面已經搞定了,下篇就是界面設計和將解析的數據放在界面上了。
一.支付寶支付1. 集成說明1.1 作為當下最熱門的支付寶和微信支付,相信有很多的app都很樂意的將支付寶集成在app中,畢竟只要你開發的app有一點涉及到買賣的,都需要
andriod短信整合備份發送到gmail郵箱,需要在andoid手機配置好gmail郵箱 github代碼 https://github.com/zhwj184/sms
最近很多人在玩一個《貪吃蛇大作戰》的游戲,以前小時候也經常在文曲星上玩貪吃蛇這個小游戲,於是自己就試著寫一個傳統的貪吃蛇游戲來玩玩,先寫了一個簡單demo。我們知道小蛇是
android 不同進程間的調用 AIDL 實現通訊服務 最近對aidl android 不同進程間的調用,不同運用間的調用做了一些嘗試: 步驟如下:
#1、錯誤描述今天,想實現Activity不顯示標題欄的效果,在項目的A