简体   繁体   English

koush / ion在textview中获取json

[英]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. 我试图理解Koushi-ion的代码,以便可以从网站获取json数据并将其输入到列表视图中。 for now i am testing it with just a textview. 现在,我仅使用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); 我收到logcat错误:unsupportedoperationException: JsonObject at com.google.Gson.JsonElement.getAsString(JsonElement java:191);

Is it not that simple with Ion? 用离子不是那么简单吗?

You're using Gson incorrectly. 您使用的Gson错误。 just use result.toString if you want the json as a string. 如果要将json作为字符串,则只需使用result.toString即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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