Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java gson get object without class

String jsonStr = "{"name" : "Abcd", "greeting": "Hello", }"; //Sample Json String

Gson gson = new Gson(); // Creates new instance of Gson
JsonElement element = gson.fromJson (jsonStr, JsonElement.class); //Converts the json string to JsonElement without POJO 
JsonObject jsonObj = element.getAsJsonObject(); //Converting JsonElement to JsonObject

String name = jsonObj.get("name").getAsString(); //To fetch the values from json object
String greeting = jsonObj.get("greeting").getAsString();
Source by riptutorial.com #
 
PREVIOUS NEXT
Tagged: #java #gson #object #class
ADD COMMENT
Topic
Name
7+5 =