java - Android Unhandled exception: org.json.JSONException with ion -
i'm trying json array ion (https://github.com/koush/ion) error: unhandled exception: org.json.jsonexception :(
my json:
[{"title":"hello world","text":"this text"}]
my code:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_json); ion.with(myactivity.this) .load(getstring(r.string.json_url)) .asjsonarray() .setcallback(new futurecallback<jsonarray>() { @override public void oncompleted(exception e, jsonarray result) { if (e != null) { toast.maketext(myjson.this, "error loading strings", toast.length_long).show(); return; } jsonobject c = result.getjsonobject(0); if (c.has("title")) title = c.getstring("title"); if (c.has("text")) text = c.getstring("text"); } }); }
can tell me did wrong, please? :(
edit:
error:(48, 17) error: method setcallback in interface future<t> cannot applied given types; required: futurecallback<jsonarray> found: <anonymous futurecallback<jsonarray>> reason: actual argument <anonymous futurecallback<jsonarray>> cannot converted futurecallback<jsonarray> method invocation conversion t type-variable: t extends object declared in interface future
i solved problem guys :)!
i changed: jsonarray (org.json.jsonarray) to: jsonarray (com.google.gson.jsonarray)
and added this:
jsonobject c = result.get(0).getasjsonobject();
this code now:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_json); ion.with(myactivity.this) .load(getstring(r.string.json_url)) .asjsonarray() .setcallback(new futurecallback<jsonarray>() { @override public void oncompleted(exception e, jsonarray result) { if (e != null) { toast.maketext(myjson.this, "error loading strings", toast.length_long).show(); return; } jsonobject c = result.get(0).getasjsonobject(); if (c.has("title")) title = c.get("title").getasstring(); if (c.has("text")) text = c.get("text").getasstring(); } }); }
this solved problem!
Comments
Post a Comment