我需要解析下面給出的JSON數據。如何解析JSON字符串的值爲數組
{"result":[{"bookId":142645,"bookpb":"MF",
"bookTs":1328999630000,"clipStatus":"D","bookDetail":{"arrival":1,"purchase":1,"sold":1},
"hierarchies":{"categories":["4"],"events":[]},"shopId":769752},
upto「sold」it working fine.but當我試圖解析類別它不工作。下面給出的 是解析數據的代碼。
ArrayList<BookItem> resultdata = new ArrayList<BookItem>();
JSONArray jsonArray = (new JSONObject(inputString))
.getJSONArray("result");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
item = new BookItem();
item.setbookId(jsonObject.optString(book_ID));
item.setPurchase(jsonObject.optInt(PURCHASE));
item.setArrival(jsonObject.optInt(ARRIVAL));
item.setSold(jsonObject.optInt(SOLD));
item.setbookTs(jsonObject.optString(book_TS));
JSONObject hierarchies=jsonObject.getJSONObject(HIERARCHY);
item.setCategory(hierarchies.getInt("categories"));
resultdata.add(item);
}
任何人都可以幫我嗎?
我才知道,這是
{"categories":["4"],"events":[]}
data.how的我可以分析該數組值的問題?
它始終是最好用HTTP檢查您的JSON字符串:// jsonlint。 com /如果它很複雜。這似乎是提到的一個是不正確的格式 – dhaval 2012-03-20 11:56:29
PLZ幫助我..我卡在這.. – 2012-03-20 12:51:53