0

我正在尝试理解 Koushi-ion 的代码,以便我可以从网站获取 json 数据并将其输入到列表视图中。现在我只用一个文本视图来测试它。

@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);
            }

我收到 logcat 错误:unsupportedoperationException: JsonObject at com.google.Gson.JsonElement.getAsString(JsonElement java:191);

离子不是那么简单吗?

4

1 回答 1

0

您错误地使用了 Gson。如果您希望 json 作为字符串,只需使用 result.toString 。

于 2014-04-13T01:47:03.623 回答