我需要解析下面给出的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