以下是我的JSON。我需要在" newsdetail"中解析news_title。来自类别列表对象。解析这些数据的正确方法是什么?请帮帮我。
{"categorylist":[{"process":"news","ncid":"1"","newsdetail":[{"newsid":"604","category":"1","category_title":"","news_title":"just"},{"newsid":"606","category":"1","category_title":"","news_title":"fg"}]},{"process":"news","ncid":"2","newsdetail":[{"newsid":"477","category":"2","category_title":"","news_title":"way},{"newsid":"478","category":"1","category_title":"","news_title":"k"}]}
答案 0 :(得分:1)
{"categorylist":[{"process":"news","ncid":"1"" // cannot be double quotes come here.
,"newsdetail":[{"newsid":"604","category":"1","category_title":"","news_title":"just"},{"newsid":"606","category":"1","category_title":"","news_title":"fg"}]},{"process":"news","ncid":"2","newsdetail":[{"newsid":"477","category":"2","category_title":"","news_title":"way},{"newsid":"478","category":"1","category_title":"","news_title":"k"}]}
你可以使用下面的光标..但你的字符串数据有一些问题
try {
JSONObject jsonObject = new JSONObject(data);
JSONArray category_list = jsonObject.getJSONArray("category_list");
for (int i = 0; i < category_list.length() ; i++) {
// here you get news title for each news
String newsTitle = category_list.getJSONObject(i).getString("news_title");
}
}catch (JSONException e){
}