0

I'm trying to understand Koushi-ion's code so that i can get json data from website and input it into a listview. for now i am testing it with just a textview.

@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.testview);
        test = (TextView)findViewById(R.id.testview1);

        Ion.with(getApplication(), "mywebsite")
        .asJsonObject()
        .setCallback(new FutureCallback<JsonObject>() {
           @Override
            public void onCompleted(Exception e, JsonObject result) {
                // do stuff with the result or error
               inputTest = result.getAsString();
               test.setText(inputTest);
            }

i get the logcat error :unsupportedoperationException: JsonObject at com.google.Gson.JsonElement.getAsString(JsonElement java:191);

Is it not that simple with Ion?

crushman
  • 1,023
  • 9
  • 21

1 Answers1

0

You're using Gson incorrectly. just use result.toString if you want the json as a string.

koush
  • 2,972
  • 28
  • 31
  • Just gives null pointer exception. Im really just shooting in the dark here cuz i have no idea how to use this Library for anything other than images. How do i parse data to a textview with this? theres absolutely no documentation whatsoever on this. – crushman Apr 24 '14 at 03:29
  • You likely have an exception then. Check the exception value "e". There's plenty of javadoc and examples as well: https://github.com/koush/ion#get-json If you have questions on how to use Gson, that's a Gson question, not Ion. – koush Apr 27 '14 at 01:22
  • @crushman , if you got the answer on **how to set json into a textview**, please share it with am having the same problem – Lutaaya Huzaifah Idris Oct 12 '16 at 12:30
  • @koush , please you too help me out am new in using **ion**, you can check out my question here http://stackoverflow.com/questions/39996356/setting-json-data-to-a-textview-using-ion-library – Lutaaya Huzaifah Idris Oct 12 '16 at 12:32