Create object from JSON with Parse & Java for Android -
Create object from JSON with Parse & Java for Android -
i have started doing android development, using parse.com , native java building app. trying figure out how create objects created json result via callback parse parse.com.
{ "result": { "count": 3, "lang": "en-us", "tasks": [ { "id": "0123", "name": "task 1", "assingedto": "darxval", "scope": "home" }, { "id": "0124", "name": "task 2", "assingedto": "darxval", "scope": "home" }, { "id": "0125", "name": "task 3", "assingedto": "darxval", "scope": "home" } ] } }
the method phone call via parse shown below. (see documentation more info on method here):parse documentation
parsecloud.callfunctioninbackground("retrievetasks", new hashmap<string, object>(), new functioncallback<object>() { void done(object result, parseexception e) { if (e == null) { // stuff object } } });
i have tried alter function callback class takes in json described bunch of strings , listarray of task objects. not create object. want utilize hashmap. there way turn info object want instead of hashmap? there interface need "implement" on objects allow creation of object on callback?
any help in appreciated.
what object added hashmap? jsonobject? if so, can convert jsonobject whatever custom object looking using constructor, , info jsonobject.
for example, if jsonobject returned called "output":
seek { jsonobject result = output.getjsonobject("result"); int count = result.getint("count"); string lang = result.getstring("lang"); jsonarray tasks = result.getjsonarray("tasks"); jsonobject firstobjectinarray = tasks.getjsonobject(0); string firstid = firstobjectinarray.getstring("id"); } grab (jsonexception e) { e.printstacktrace(); }
etc.
then utilize constructor object create new object:
object obj = new object(count, lang, firstid);
etc.
for more information
java android json parse.com
Comments
Post a Comment