Saturday 15 February 2014

Parse Json with Jackson Android -



Parse Json with Jackson Android -

i´m developing app uses lot of json, using gson parse, slow , i´m trying utilize jackson, it´s first time heard of it, don´t know how utilize well. json it´s like:

{ "action": "login", "status": true, "message": "ok", "duration": 144, "response": { "token": "b6a1e3b87c86531d91afa91bb23aca46" } }

and class deserialize it´s like:

public class httpwebserviceobject { private string action; private boolean status; private string message; private string duration; private string response; //getters , setters }

someone help me this?

thanks in advance.

edited:

i can have json too:

{ "action": "getuserfollowers", "status": true, "message": "ok", "duration": 187, "response": [ { "id": "20810", "name": "thyago", "username": "thyago", "location": "guarujá,brasil", "photo": "profile/48d15179063126b40f6a5b1bbdea7f1e.jpg", "following": false, "numfollowing": 3, "numfollowers": 7 }, { "id": "933", "name": "edson alves", "username": "prazermatheus", "location": "rio de janeiro, brasil.", "photo": "profile/bcc90c29054781adcd4569bb59251dba.jpg", "following": false, "numfollowing": 2689, "numfollowers": 1373 }, { "id": "753", "name": "yasmim teófilo", "username": "yasmim_gomesz", "location": "pacajus, brasil", "photo": "/profile/default.png", "following": false, "numfollowing": 1, "numfollowers": 6 }, { "id": "531", "name": "muriel aragão", "username": "muriaragao", "location": "salvador, brasil", "photo": "profile/0f6b504736723ea80c9cd15dabb3f0c5.jpg", "following": false, "numfollowing": 348, "numfollowers": 32 }, { "id": "492", "name": "shashank", "username": "shashank", "location": "india", "photo": "/profile/default.png", "following": false, "numfollowing": 5, "numfollowers": 3 }, { "id": "307", "name": "clineu iansen", "username": "clineu", "location": "curitiba, brazil", "photo": "profile/3d37a1e9c795a83c672ecacf575ee30a.jpg", "following": false, "numfollowing": 57, "numfollowers": 946 }, { "id": "277", "name": "maharshi", "username": "india", "location": "india", "photo": "profile/86d403617a30469f11403f0c9c65141b.jpg", "following": true, "numfollowing": 16, "numfollowers": 1848 }, { "id": "57", "name": "alexandre", "username": "xandyhsf", "location": "itajai, brasil", "photo": "/profile/default.png", "following": false, "numfollowing": 51, "numfollowers": 16 }, { "id": "34", "name": "karina ceconello ton", "username": "karinaceconello", "location": "quatro barras/brasil", "photo": "profile/9bc1fb97263dc9a242766c87e4acf1c4.jpg", "following": false, "numfollowing": 5, "numfollowers": 198 }, { "id": "25", "name": "thiago bodruk", "username": "thiagobodruk", "location": "quatro barras, brazil", "photo": "profile/56111881a4ebe0f0fc5cb85faa262e17.jpg", "following": false, "numfollowing": 26, "numfollowers": 221 } ] }

how general parse deseriliaze , take response string?

first alter pojo this

public class httpwebserviceobject { private string action; private boolean status; private string message; private string duration; private response response; // json string object. not string. create seperate pojo response //getters , setters

}

then can utilize objectmapper convert java objects json string. illustration

objectmapper mapper = new objectmapper(); httpwebserviceobject httpwebserviceobject = mapper.readvalue(yourjsonstring,httpwebserviceobject.class);

android json parsing object jackson

No comments:

Post a Comment