parsing JSON using "koush/ion" not working?

349 Views Asked by At

*the JsonObject json is empty, but result in onCompleted function works fine and correctly returns json data but I can't use it outside the oncompleted function *

   final JsonObject json = new JsonObject();
            Ion.with(MainActivity.this)
                    .load("https://wordsapiv1.p.mashape.com/words/" + searchedWord)
                    .setHeader("X-Mashape-Key","I've hidden the Key !")
                    .asJsonObject()
                    .setCallback(new FutureCallback<JsonObject>() {
                        @Override
                        public void onCompleted(Exception e, JsonObject result) {
                            Log.i("result: ","" + result);
                            Log.i("json: ", "" + json);
                        }
                    });
1

There are 1 best solutions below

2
On BEST ANSWER

I don't understand why you need the first line?

final JsonObject json = new JsonObject();