Tuesday, September 27, 2016

How to Use GSON in Android Studio

To add GSON to your project 

just add 

dependencies {compile 'com.google.code.gson:gson:2.3'}

then to add GSON plugin to your Android studion IDE
preset CTRL+ALT+S to open settings 
then go to plugins
then search for GSON(if you dont find it you need to download GSONFORMAT.jar)
once you install and restart Studio
Just create a empty class ALT+Insert  + ALT+S will open a window 
in which expected JSON you will paste
according to that JSON format your class will be created.

To use in code
Gson gson= new Gson();
Yourclass ref=gson.fromJson(json,YourClass.class);
String item=   ref.getName();