我有String witj Json:
String str = "[{
"serviceid": "312",
"servicetype": "0",
"nextrecurringchargedate": "null"
},
{
"serviceid": "104",
"servicetype": "0",
"nextrecurringchargedate": "null"
},
{
"serviceid": "310",
"servicetype": "0",
"nextrecurringchargedate": "null"
}]";
我有模特:
public class NextChDay {
@SerializedName("serviceid")
private Long serviceId;
@SerializedName("servicetype")
private Long serviceType;
@SerializedName("nextrecurringchargedate")
private Date nextrecurringchargedate;
public NextChDay() {
}
public NextChDay(Long serviceId, Long serviceType, Date nextrecurringchargedate) {
this.serviceId = serviceId;
this.serviceType = serviceType;
this.nextrecurringchargedate = nextrecurringchargedate;
}
// getters and setters
我希望将Json转换为模型使用GSON库
NextChDay[] nextChDays = GSON.fromJson(str, NextChDay[].class);
但我有一个错误:
java.text.ParseException: Unparseable date: "null"
以前,我对“null”没有任何问题,我不明白如何解决这个问题。请帮帮我。
答案 0 :(得分:1)
值null
是JSON中的保留字/值,因此不应该用引号或双引号括起来。当它被包装时,它实际上被认为是包含字符n
,u
,l
和l
的字符串值。
所以,试着替换这一行:
"nextrecurringchargedate": "null"
这一行:
"nextrecurringchargedate": null