0
我需要填充來自JSON數組「視頻」中標記「group」下的數據的列表視圖。它下面的編碼工作正常,如果我刪除條件。請幫助我們。我的老闆正在踢我的屁股,因此我的工作就緒。在此先感謝從填充列表中獲取json服務的具體數據列表
公共類CountryJSONParser {
// Receives a JSONObject and returns a list
public List<HashMap<String,Object>> parse(JSONObject jObject){
JSONArray jCountries = null;
try {
// Retrieves all the elements in the 'countries' array
jCountries = jObject.getJSONArray("video");
}
catch (JSONException e) {
e.printStackTrace();
}
// Invoking getCountries with the array of json object
// where each json object represent a country
return getCountries(jCountries);
}
private List<HashMap<String, Object>> getCountries(JSONArray jCountries){
int countryCount = jCountries.length();
List<HashMap<String, Object>> countryList = new ArrayList<HashMap<String,Object>>();
HashMap<String, Object> country = null;
// Taking each country, parses and adds to list object
for(int i=0; i<countryCount;i++){
try {
// Call getCountry with country JSON object to parse the country
country = getCountry((JSONObject)jCountries.get(i));
countryList.add(country);
} catch (JSONException e) {
e.printStackTrace();
}
}
return countryList;
}
// Parsing the Country JSON object
private HashMap<String, Object> getCountry(JSONObject jCountry){
HashMap<String, Object> country = new HashMap<String, Object>();
String countryName = "";
String flag="";
String language = "";
String capital = "";
String currencyCode = "";
String currencyName = "";
try {
countryName = jCountry.getString("Description");
flag = jCountry.getString("thumbnailUrl");
capital = jCountry.getString("title");
language=jCountry.getString("group");
Log.v("---","Country name: "+countryName+"Flag Url:"+flag+"Title"+capital);
if(language.equals("RokuTest-VideoGroup")){
country.put("country", countryName);
country.put("group", language);
country.put("flag", R.drawable.ic_launcher);
country.put("flag_path", flag);
country.put("details", capital);
Log.v("---","Country name: "+countryName+"Flag Url:"+flag+"Title"+capital);
}
} catch (JSONException e) {
e.printStackTrace();
}
return country;
}
}
沒有任何工作。嘗試了不同的東西。還是一樣。 – 2014-10-12 09:11:35
你是否在日誌貓中得到任何錯誤?你能給你解析的JSON響應嗎? – 2014-10-12 09:32:04
檢查語言的價值,它包含什麼並打印日誌。我建議爲JSON解析創建單獨的類。看起來,如果你使用塊,條件是假的,值不能存儲在國家哈希映射。 – 2014-10-12 10:02:06