【发布时间】:2014-02-23 20:58:34
【问题描述】:
我有以下 JSON(来自 URL)
["Rock","Rock Argentino","Reggaeton","En Español","Reggaeton ","Reggaeton ","Boleros","Italianos ","Cumbias ","Cumbia ","Internacional","Internacional "]
您可以看到这些字段没有“名称属性”。
我的班级模型如下
public class KaraokeCategoryModel {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
但 GSON 没有重新识别我的属性“名称”
Type karaokeCollection = new TypeToken<Collection<KaraokeCategoryModel>>() {}.getType();
_karaoke_cartegory_response = new Gson().fromJson(reader, karaokeCollection);
稍后我创建适配器
_karaoke_category_adapter = new KaraokeCategoryAdapter(getSupportActionBar().getThemedContext(), R.layout.spinner_item, _karaoke_cartegory_response);
getSupportActionBar().setListNavigationCallbacks(_karaoke_category_adapter, this);
我应该怎么做才能让 GSON 使用我的模型没有问题?
【问题讨论】:
-
为什么不把它读成
List<String>并为每个字符串创建一个KaraokeCategoryModel对象呢? (您需要为您的类创建一个构造函数。) -
@ChthonicProject 使用该选项创建适配器是否复杂??
-
我看不出根据您创建
KaraokeCategoryModel的方式创建适配器会如何变化。