改造 + GSON 解串器
Retrofit + GSON deserializer
我有一个这样的对象:
"choice": {
"000": {
"id": "001",
"label": "test",
"status": "0"
},
"001": {
"id": "001",
"label": "test",
"status": "0"
},
"002": {
"id": "001",
"label": "test",
"status": "0"
},
"003": {
"id": "001",
"label": "test",
"status": "0"
},
"004": {
"id": "001",
"label": "test",
"status": "0"
}
},
如何使用 Gson+Retrofit 解析该对象?或者生成一个POJO?有简单的方法吗?
非常感谢!
您所选择的所有对象 json 的主要思想是 Map:
public class RootObject{
Map <String,ChoiceEntry> choice;
}
public class ChoiceEntry{
String id;
String label;
int status;
}
您可以通过将 JSON 代码粘贴到此 link 中来创建 POJO:http://pojo.sodhanalibrary.com/。
您发布的代码段格式不正确。我相信您将拥有一个多 class POJO,并且对于某些用途(如列表视图)来说很难处理。
让我知道进展如何。 Retrofit 真的很好用,但弄清楚非常烦人!
intellij/android 工作室有一个 addon 可以轻松生成 POJO。
免责声明:我与该项目没有任何关系。
我有一个这样的对象:
"choice": {
"000": {
"id": "001",
"label": "test",
"status": "0"
},
"001": {
"id": "001",
"label": "test",
"status": "0"
},
"002": {
"id": "001",
"label": "test",
"status": "0"
},
"003": {
"id": "001",
"label": "test",
"status": "0"
},
"004": {
"id": "001",
"label": "test",
"status": "0"
}
},
如何使用 Gson+Retrofit 解析该对象?或者生成一个POJO?有简单的方法吗?
非常感谢!
您所选择的所有对象 json 的主要思想是 Map:
public class RootObject{
Map <String,ChoiceEntry> choice;
}
public class ChoiceEntry{
String id;
String label;
int status;
}
您可以通过将 JSON 代码粘贴到此 link 中来创建 POJO:http://pojo.sodhanalibrary.com/。
您发布的代码段格式不正确。我相信您将拥有一个多 class POJO,并且对于某些用途(如列表视图)来说很难处理。
让我知道进展如何。 Retrofit 真的很好用,但弄清楚非常烦人!
intellij/android 工作室有一个 addon 可以轻松生成 POJO。
免责声明:我与该项目没有任何关系。