Afegiu a les dependències de Gradle:
dependencies { compile 'com.koushikdutta.ion:ion:2.+' }
I feu click a sync Now.
Ion.with(this) .load("http://acacha.github.io/json-server-todos/db_todos.json") .asJsonArray() .setCallback(new FutureCallback<JsonArray>() { @Override public void onCompleted(Exception e, JsonArray result) { // do stuff with the result or error todoList = result.toString(); Log.d("TAG_PROVA AAAA ", todoList); do_something_with_result(); } });
Ion.with(context) .load("http://acacha.github.io/json-server-todos/db_todos.json") .asJsonObject() .setCallback(new FutureCallback<JsonObject>() { @Override public void onCompleted(Exception e, JsonObject result) { // do stuff with the result or error } });
Ion.with(context, "http://example.com/thing.json") .asJsonObject() .setCallback(new FutureCallback<JsonObject>() { @Override public void onCompleted(Exception e, JsonObject result) { // do stuff with the result or error } });
Post JSON and read JSON
JsonObject json = new JsonObject(); json.addProperty("foo", "bar"); Ion.with(context, "http://example.com/post") .setJsonObjectBody(json) .asJsonObject() .setCallback(new FutureCallback<JsonObject>() { @Override public void onCompleted(Exception e, JsonObject result) { // do stuff with the result or error } });