How to parse JSON in Java and put values into Collection -


this question has answer here:

is there way in java in can read json , directly put it`s values in collection. in case have 3 different type. can make :

collection<type> types;  

json :

{ "type1":[       {         "version": "1.11",         "releasedate": "2015-03-26",         "downloadurl": "****"       },       {         "version": "1.12",         "releasedate": "2015-04-08",         "downloadurl": "****"       }], "type2":[       {         "version": "2.20",         "releasedate": "2015-03-26",         "downloadurl": "****"       },       {         "version": "2.21",         "releasedate": "2015-04-08",         "downloadurl": "****"       }], "type3":[       {         "version": "2.56",         "releasedate": "2015-03-26",         "downloadurl": "****"       },       {         "version": "2.57",         "releasedate": "2015-04-08",         "downloadurl": "****"       }] } 

you can using gson. i'm giving basic idea change per requirements datatype, conventions, etc...

public class yourtype{  private string version;  private string releasedate;  private string downloadurl;  // getter-setter } 

and

/* code convert json collection */ import java.lang.reflect.type; import com.google.gson.reflect.typetoken;  type objtype = new typetoken<list<yourtype>>(){}.gettype(); list<yourtype> list = objgson.fromjson(yourjsonobject.getjsonarray("type1").tostring(), objtype); 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -