簡體   English   中英

koush / ion在textview中獲取json

[英]koush/ion getting json in in textview

我試圖理解Koushi-ion的代碼,以便可以從網站獲取json數據並將其輸入到列表視圖中。 現在,我僅使用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);
            }

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

用離子不是那么簡單嗎?

您使用的Gson錯誤。 如果要將json作為字符串,則只需使用result.toString即可。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM