2016-04-23 84 views
2

JSON的樣子:如何通過JSON鍵獲取值?

{ 
    "cover":"blabla.jpg", 
    "content":[ 
     { 
     "article":"article_text", 
     "document":"document_text" 
     } 
    ] 
} 

我知道如何讓"cover"

JSONObject json = new JsonObject(jsonStr); //jsonStr - мой json в видео строки  
json.get("cover"); 

但我怎麼能由"article"關鍵值?

+0

當你'json.get( 「內容」),你這話是什麼得到什麼? – bili

+0

@bili我得到了JSONArray包含String' [{「document」:「document_text」,「article」:「article_text」}]'' –

回答

4

哦,我做到了。謝謝。

json.getJSONArray("content").getJSONObject(0).getString("article") 
4

你可以嘗試這樣的事情:

yourJSonObject.getJSONObject("cover").getJSONObject("content").getJSONObject("article");