我試圖使用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
回覆已更新 –