使用GSON列出的JSONArray

时间:2015-04-23 18:58:55

标签: android arrays gson

我有一个这样的数组:

[{"poolkost":"IWXI"},{"poolkost":"ILXI"},{"poolkost":"VGXI"}]

并希望使用教程How to convert JSONArray to List with Gson?

将其放入列表中

我的代码:

    String jsonStr = DBFunction.GetBoxer(GlobalClass.DIR);
    Gson gson = new Gson();
    Type listType = new TypeToken<List<String>>(){}.getType(); //ERROR 1
    List<String> PoolList = gson.fromJson(jsonStr, listType);  //ERROR 2

我收到2个错误:

错误1:

Type mismatch: cannot convert from java.lang.reflect.Type to android.renderscript.Type

错误2:

The method fromJson(String, Class<T>) in the type Gson is not applicable for the arguments (String, Type)

我无法修复第一个错误,要么是第二个......

1 个答案:

答案 0 :(得分:1)

检查您的进口。

删除它:

import android.renderscript.Type;

添加:

import java.lang.reflect.Type;

这应解决这两个问题。

相关问题