android - parsing json array which is returned as object using retrofit -
how can parse following response api using retrofit lib in android?
{ "elements": { "12": { ... }, "23": { ... }, "32": { ... } }, "more": null }
here elements json object needed array.
here trying
public static class elementresponsedeserializer implements jsondeserializer<elementresponse>{ @override public elementresponse deserialize(jsonelement json, type typeoft, jsondeserializationcontext context) throws jsonparseexception { logger.d("json >>>> typeoft" + typeoft.tostring()); logger.d("json >>>> context" + context.tostring()); logger.d("json >>>> " + json.tostring()); jsonobject object = json.getasjsonobject(); object.get return new elementresponse(); } }
and using way
gson gson = new gsonbuilder() .registertypeadapter(elementsresponse.class, new elementsresponsedeserializer()) .create(); restadapter restadapter = new restadapter.builder() .setclient(new okclient(client)) .setendpoint(url_api) .setconverter(new gsonconverter(gson)) .setrequestinterceptor(new apirequestinterceptor()) .build(); restadapter.setloglevel(restadapter.loglevel.full); return restadapter.create(myapp.class);
Comments
Post a Comment