java - Is there efficient way to convert org.json.JSONObject to POJO model using GSON? -
is there efficient way convert org.json.jsonobject pojo model using gson ? (at moment u thought
gson g=new gson(); g.fromjson(json.tostring(), personmodel.class);
json jsonobject
). using volley , in response instance of jsonobject , can parse on http://www.kpbird.com/2013/05/volley-easy-fast-networking-for-android.html have complex structure in models nested lists , avoid manual extracting of data json.
first, sorry bumping old question.
i asking myself same question , found example in android volley section called implementing custom requests in android developer site.
@override protected response<t> parsenetworkresponse( networkresponse response) { try { string json = new string(response.data, httpheaderparser.parsecharset(response.headers)); return response.success(gson.fromjson(json, clazz), httpheaderparser.parsecacheheaders(response)); } // handle errors ... }
i use stringrequest , use gson on response callback, should faster getting jsonobject , converting string prior calling gson. see in jsonobject javadoc there's no way create instance byte[], http response in bytes converted string, jsonobject, , convert string again. using stringrequest can skip last 2 steps.
Comments
Post a Comment