2016-07-03 146 views
0

以下是我的JSON。我需要从类别列表对象的“newsdetail”中解析news_title。解析这些数据的正确方法是什么?请帮帮我。Json数组和对象解析

{"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

你'JSON'无效。在此处更改 - > http://www.jsoneditoronline.org/ –

+0

您是否尝试过自己解析此json? –

+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"}]} 

您可以使用下面parsor ..但你的字符串的数据有一些问题

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){ 

       }