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.
String myJSONString = "{'test': '100.00'}"; JsonObject jobj = new Gson(). fromJson(myJSONString, JsonObject. class); String result = jobj. get("test").
Use JSONObject. keys() which returns an iterator of the String names in this object. then use these keys to retrieve values.
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 .
String loudScreaming = json.getJSONObject("LabelData").getString("slogan");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With