Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get value by key from JSON?

Tags:

java

json

JSON looks like:

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

I know how to get "cover":

JSONObject json = new JsonObject(jsonStr);
json.get("cover");

But how can I get value by "article" key?

like image 930
Artyom Chebotaryov Avatar asked Apr 23 '16 15:04

Artyom Chebotaryov


2 Answers

You can try something like this:

yourJSonObject.getJSONObject("cover").getJSONObject("content").getJSONObject("article");
like image 143
Pritam Banerjee Avatar answered Nov 09 '22 08:11

Pritam Banerjee


Oh, i did it. Thanks.

json.getJSONArray("content").getJSONObject(0).getString("article")
like image 36
Artyom Chebotaryov Avatar answered Nov 09 '22 10:11

Artyom Chebotaryov