我有以下JSON:
{
"Person": {
"id": "1",
"name": "sampleName"
},
"PersonCalender ": {
"start": "2017-01-25T19:00:00+0100",
"End": "2019-05-10T19:00:00+0100"
}
}
这是它对应的Java
对象(包含2个对象):
public class PersonRequest {
private Person person;
private PersonCalender personCalender;
//getters and setters
}
下面显示了我如何尝试parse
对象,但只有Person对象被正确解析。
我是否犯了错误或使用JSON
将Gson
无效解析为此对象?
Gson Parsing:
PersonRequest personRequest = new PersonRequest();
try {
InputStream is = PersonTest.class.getResourceAsStream("/my/path/personRequest.json");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
Gson gson = new Gson();
personRequest = gson.fromJson(bufferedReader, PersonRequest.class);
} catch (Exception e) {
logger.logMessage("Exception: " + e);
}
答案 0 :(得分:1)
这里有两个错误。 1 - MAX
之后的空格,2- PersonCalender
中的第一个字母应为小写(根据您的java代码)