mercredi 1 avril 2015

I am having Json String this way,



json= [{"id":"1","label":"2","code":"3"},{"id":"4","label":"5","code":"6"}]


I tried converting it into Java Object this way, by using Gson,


and a Pojo called Item.java with fields namely id,label and code and getter setters for them.



String id;
String label;
String code;
//getter setters

Gson gson = new Gson();
List<Item> items = gson.fromJson(json, new TypeToken<List<Item>>(){}.getType());


Then converted Java Object to List this way,



List<String> strings = new ArrayList<String>();
for (Object object : items) {
strings.add(object != null ? object.toString() : null);
}


My output is this way,



[Item [id=1, label=2, code=3], Item [id=6, label=5, code=6]


But i need it as List<List<String>> and without [Items] i.e,



[[id=1, label=2, code=3],[id=4, label=5, code=6]]

or direct



List<List<String>>


without key.



[[1, 2, 3],[4, 5, 6]]


What is that I am missing? Can some body help me in this?


Aucun commentaire:

Enregistrer un commentaire