我的Google Json arrylist返回0值,但不应该。
我不希望返回这个值,如:
此 - "总":0,"记录":0,"页面":0,"行":0,
下面的代码返回此数组:
[
{
"message":"sdfghjkl",
"total":0,
"records":0,
"page":0,
"rows":0
},
{
"message":"knee problem",
"total":0,
"records":0,
"page":0,
"rows":0
},
{
"message":"hip problem",
"total":0,
"records":0,
"page":0,
"rows":0
},
{
"message":"patient message",
"total":0,
"records":0,
"page":0,
"rows":0
},
{
"message":"hip problem 2-12-2015",
"total":0,
"records":0,
"page":0,
"rows":0
},
{
"message":"hip problem 12-2015",
"total":0,
"records":0,
"page":0,
"rows":0
}
]
代码:
Gson gson = new Gson();
List<PatientDto> all_pati_message = new ArrayList<PatientDto>();
String sql = "";
try {
sql = "SELECT message from patient_mess";
ResultSet rs;
rs = DatabaseConn.getConnection().createStatement().executeQuery(sql);
while (rs.next()) {
PatientDto dto1 = new PatientDto();
dto1.setMessage(rs.getString(1));
all_pati_message.add(dto1);
}
} catch (Exception e) {
e.printStackTrace();
}
String jsonString = gson.toJson(all_pati_message);
return jsonString;
&#13;
答案 0 :(得分:0)
GsonBuilder builder = new GsonBuilder(); builder.excludeFieldsWithoutExposeAnnotation(); final Gson gson = builder.create();
并在你的dto类PatientDto
中使用google json的注释,如@Expose private String message