【发布时间】:2017-03-31 18:34:18
【问题描述】:
我正在尝试使用 GSON 将 JSON 值映射到 POJO。当我尝试从 JSON 字符串中取回对象时,所有变量都设置为 null。
这是我的代码
Pojo.java
public class PatientSymptoms {
private Integer AnalSymptomsMapId;
private Integer SymptomId;
private String Symptom;
private Boolean IsRemoved;
private Boolean IsSynced;
private Boolean IsSentToPatient;
//Getters and Setters
}
映射代码
JSONObject jsonObject = (JSONObject) jsonArray.get(i);
PatientSymptoms symptoms = new PatientSymptoms();
Gson gson = new Gson();
String x = gson.toJson(jsonObject);
symptoms = gson.fromJson(x,PatientSymptoms.class);
但PatientSymptoms 对象值始终为空。这是调试器的屏幕截图
更新 JSON响应
{
"Success": true,
"StatusCode": 0,
"StatusMessage": "",
"Data": [
{
"AnalSymptomsMapId": 250,
"SymptomId": 95,
"Symptom": "asdf",
"IsRemoved": false,
"IsSynced": false,
"IsSentToPatient": true
}
]
}
【问题讨论】:
-
实现 Parcelable。
-
请发布您的 json
-
回复已更新
标签: android json jackson gson pojo