How to convert Json to Java object using Gson -


this question has answer here:

suppose have json string

{"userid":"1","username":"yasir"} 

now have class user

class user{ int userid; string username; //setters , getters } 

now how can convert above json string user class object

try this:

gson gson = new gson(); string jsoninstring = "{\"userid\":\"1\",\"username\":\"yasir\"}"; user user= gson.fromjson(jsoninstring, user.class); 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -