【发布时间】:2020-01-25 20:45:38
【问题描述】:
我想在 Theme 对象中解析我的 json:
结果:
["[\"1\",\"Alternant\"]","[\"2\",\"DevOps\"]"]
方法getListTheme:
Future<List<String>> getListTheme() async {
List<String> themes = List<String>();
final SharedPreferences preferences = await SharedPreferences.getInstance();
for (String key in preferences.getKeys()) {
if (key == 'token') {
preferences.containsKey(key);
} else {
themes.add(jsonEncode(preferences.getStringList(key)));
}
}
return themes;
}
其他代码:
await Theme().getListTheme().then((value){
theme = jsonEncode(value);
});
我的主题课:
class Theme {
int id;
String name;
Theme({this.id, this.name});
factory Theme.fromJson(Map<String, dynamic> json) {
return Theme(
id: json['id'],
name: json['name'],
);
}
}
如何解析主题对象中的结果?
【问题讨论】:
-
有问题吗?
-
["[\"1\",\"Alternant\"]","[\"2\",\"DevOps\"]"] 我想用 id 在对象主题中解析这个/名称@AndresCastro
标签: android mobile flutter flutter-layout