简体   繁体   中英

koush/ion getting json in in textview

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM