Search
 
SCRIPT & CODE EXAMPLE
 

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();
Comment

PREVIOUS NEXT
Code Example
Java :: electron driver window maximize selenium webdriver 
Java :: java Optional to Collection 
Java :: use scanner class in global scope java 
Java :: how to secure specific url in spring security 
Java :: create generator hibernate 
Java :: Bad JNI version returned from JNI_OnLoad in 
Java :: create object of hashMap 
Java :: rules for naming variables in java 
Java :: imagebutton get background color programmatically 
Java :: plot vector field in java 
Java :: android java onUpgrade() 
Java :: near "@gmail": syntax error 
Java :: how do you rate yourself in java 
Java :: compare string length of two strings 
Java :: edit xmlns attribute with jaxb marshaller 
Java :: SpringBootStarter maven dependency 
Java :: android studio java catch empty button 
Java :: Stringbuilser 
Java :: android java update image dynamically 
Java :: ArrayList go to value jav 
Java :: using new to create arrays 
Java :: a multi-value map, Map<K, Collection<V, supporting multiple values per key 
Java :: permuatrion sequence 
Java :: null pointer exception during registering user to the firebase 
Java :: how to change text of textview in slide menu bar header android 
Java :: usaco 2018 january contest 
Java :: array erstellen java 
Java :: spring security specific url for specific account 
Java :: java enum name() 
Java :: jdbc api in java 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =