在build.gradle中參考如下
dependencies{
implementation 'net.sf.json-lib:json-lib:2.2.3:jdk15'
//json object
implementation 'commons-beanutils:commons-beanutils:1.9.3'
implementation 'commons-collections:commons-collections:3.2.1'
implementation 'commons-lang:commons-lang:2.6'
implementation 'net.sf.ezmorph:ezmorph:1.0.6'
}
通過Map的鍵值映射保存資訊
private Map<String, Object> getTodayWeather(String datas) {
//datas為從Web端獲取的String
Map<String, Object> map = new HashMap<String, Object>();
JSONObject jsonData = https://www.cnblogs.com/MarkDespite/p/JSONObject.fromObject(datas);
//將String轉換為jsonData
JSONObject info = jsonData.getJSONObject("data");
//獲取名為data的資料塊
JSONObject ObserveInfo = info.getJSONObject("observe");
//獲取data資料塊內部的observe資料塊
map.put("Degree", ObserveInfo.getString("degree").toString());
//獲取鍵值為degree的資料,并保存在Map中(鍵值為"Degree")
return map;
}
通過Map獲取資訊
String text = responseText;
Map<String,Object> map = getTodayWeather(text);
//處理獲取的資訊
String DegreeText=(map2.get("Degree") + "℃" );
//通過Map得到資料
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/504545.html
標籤:Android
