2013-11-26 57 views
-1

我需要從我的android應用程序訪問json數據。爲此我開發了代碼。現在我有一個小問題。但我無法解決它。它給了我一個錯誤,如在圖像:Android Json傳遞問題

enter image description here

並打印我的JSON數據,它喜歡這一點。

enter image description here

,這是我的代碼。

String date = c.getString(TAG_DATE);     
String description = c.getString(TAG_DESCRIPTION); 
String title = c.getString(TAG_TITLE); 

有人能幫我嗎。

+1

我相信你在這裏看到我的回答更多地瞭解'json'以及如何解析它http://stackoverflow.com/questions/19746800/android-parse-jsonobject/19747171#19747171 –

回答

1

看起來像你忘了幫JSON對象第一

JSONObject o = c.getJSONObject("yammer"); 

String date = o.getString(TAG_DATE); 
String description = o.getString(TAG_DESCRIPTION); 
String title = o.getString(TAG_TITLE); 
+0

嘿。謝謝。我不知道我怎麼錯過它。無論如何非常感謝 – Lahiruzz

1
{ // json object node 
    "yammer": { // json object yammer 
     "date": "2012-02-03", // string 
     "description": "Lazdsasd", 
     "title": "xzx" 
    } 
} 

爲了解析

try 
{ 
    JSONObject jb = new JSONObject("your json string"); 
    String yammer = jb.getString("yammer"); 
    JSONObject jb1 = new JSONObject(yammer);  
    String date = jb1.getString("date"); 
    Log.i("date","............"+date); 
    String description = jb1.getString("description"); 
    String title = jb1.getString("title"); 
}catch(Exception e) 
{ 
     e.printStackTrace(); 
}