2016-07-03 192 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){ 

       }