我有一個JSON數組象下面這樣:的Android JSON按類別分析明智
[{"item":{"category Name":"T-e-PBS","SubCategory Name":"T-e-PBS"}},
{"item":{"category Name":"T-e-PBS","SubCategory Name":"Animals"}},
{"item":{"category Name":"T-e-PBS","SubCategory Name":"Birds"}},
{"item":{"category Name":"T-e-PBS","SubCategory Name":"Vegetables"}},
{"item":{"category Name":"T-e-PBS","SubCategory Name":"Colors"}},
{"item":{"category Name":"Rhymes","SubCategory Name":"Rhymes"}},
{"item":{"category Name":"Rhymes","SubCategory Name":"Animated Rhymes"}},
{"item":{"category Name":"Rhymes","SubCategory Name":"Cartoon Rhymes"}},
{"item":{"category Name":"Rhymes","SubCategory Name":"Prayers"}}]
我都試過,但不知道如何分類明智的信息,我有很多子類別的類別下:
我想解析這個JSON字符串並填充數據根據類別。
如果我點擊T-e-PBS按鈕,我應該可以在gridview中像GridView中的AnimalsImage,BirdsImages等那樣獲取所有子類別。
如果我點擊Rhymes類別,我應該可以在GridView中獲取所有子類別。
任何人都可以幫忙嗎?
我曾嘗試:
JSONArray ja = new JSONArray(json);
int size = ja.length();
Log.d("tag","No of Elements " + ja.length());
for (int i = 0; i < size; i++) {
String str = ja.getString(i);
}
如果您有兩個以上的子類別,該怎麼辦?你會添加他們代碼與if子句? – razielsarafan
@ santirivera92我給出了一種解決問題的方法..我們可以通過多種方式來實現......我們可以動態地存儲多個類別。 –