【发布时间】:2015-07-29 10:46:16
【问题描述】:
我是 JSON 和 GSON 的新手。我的 JSON 结构如下所述,我正在使用 gson 库来解析 json 对象并检索我从 getter 获取所有空值的值。谁能帮我解决这个问题。
JSON 文件:
{
"Samples":[
{
"Id":"XX",
"SampleId":"XX",
"Gender":"XX"
}
]
}
Java-gson 代码:
BufferedReader br = new BufferedReader(new FileReader(/mnt/ftp/sample.json));
//convert the json string back to object
patientObj = gson.fromJson(br, PatientJson.class);
patient_id=patientObj.getId();
sample_id=patientObj.getSampleId();
gender=patientObj.getGender();
患者 JSON 类:
public class PatientJson {
String id,sampleId,gender;
//with all the three getter and setters.
}
【问题讨论】:
-
显示您的 PatientJson 课程
-
@user3746601 我不太确定,但请检查字符大小写。即如果字符串是
id确保JSON 也是id而不是Id -
谁能帮我解决这个问题。使用 gson 还是 jackson API?