我试图使用GSON
将JSON
值映射到POJO。当我尝试从JSON
字符串中获取对象时,所有变量都设置为null。
这里是我的代码Android:将json值映射到pojo
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。 – Nidhi
发布你的json请 – Alexander
回复已更新 –