Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSONObject - How to get a value?

Tags:

java

json

I'm using a java class on http://json.org/javadoc/org/json/JSONObject.html.

The following is my code snippet:

String jsonResult = UtilMethods.getJSON(this.jsonURL, null); json = new JSONObject(jsonResult); 

getJSON returns the following string

{"LabelData":{"slogan":"AWAKEN YOUR SENSES","jobsearch":"JOB SEARCH","contact":"CONTACT","video":"ENCHANTING BEACHSCAPES","createprofile":"CREATE PROFILE"}} 

How do I get the value of 'slogan'?

I tried all the methods listed on the page, but none of them worked.

like image 629
Moon Avatar asked Sep 17 '11 00:09

Moon


People also ask

How do I get GSON value?

String myJSONString = "{'test': '100.00'}"; JsonObject jobj = new Gson(). fromJson(myJSONString, JsonObject. class); String result = jobj. get("test").

How do I find the first value of JSONObject?

Use JSONObject. keys() which returns an iterator of the String names in this object. then use these keys to retrieve values.

How do you check the type of a value from a JSONObject?

You can get the object from the JSON with the help of JSONObject. get() method and then using the instanceof operator to check for the type of Object. Note that it may be Integer or Long ; Float or Double .


1 Answers

String loudScreaming = json.getJSONObject("LabelData").getString("slogan"); 
like image 83
phihag Avatar answered Sep 22 '22 19:09

phihag