0
你好這是我的JSON數據錯誤獲取JSON數據
{"CategoryID":1,"CategoryName":"Clothing","Status":true,"SubCategoryList": [{"Status":true,"SubCategoryID":1,"SubCategoryName":"Male"}, {"Status":true,"SubCategoryID":2,"SubCategoryName":"Female"}, {"Status":true,"SubCategoryID":3,"SubCategoryName":"Kids"}, {"Status":true,"SubCategoryID":4,"SubCategoryName":"New Born Baby"}, {"Status":true,"SubCategoryID":11,"SubCategoryName":"Sun Glasses"}]}, {"CategoryID":2,"CategoryName":"Alcohol","Status":true,"SubCategoryList": [{"Status":true,"SubCategoryID":5,"SubCategoryName":"Wine"}, {"Status":true,"SubCategoryID":6,"SubCategoryName":"Beer"}, {"Status":true,"SubCategoryID":7,"SubCategoryName":"Scotch"}]}, {"CategoryID":3,"CategoryName":"Restourents","Status":false,"SubCategoryList": [{"Status":true,"SubCategoryID":8,"SubCategoryName":"Breakfast"}, {"Status":true,"SubCategoryID":9,"SubCategoryName":"Tour Package"}]}]
我的代碼:
JSONArray collection = new JSONArray(json1);
int length = collection.length();
for(int i=0;i<length;i++){
JSONObject row = collection.getJSONObject(i);
String value = row.getString("CategoryName");
String value6 = row.getString("SubCategoryName");
}
得到了值類別名稱:服裝,酒類,Restourents。
無法獲取SubCategoryName的值。
解析數據時出錯org.json.JSONException:SubCategoryName沒有值
如何獲取SubCategoryName的數據。
感謝會試試這個。 –