我正在使用下面的 json 文件
{
"@odata.context": "http://services.odata.org/V4/(S(ssjoqalpf5sovrqt2mkbpj2t))/TripPinServiceRW/$metadata#People('russellwhyte')/Trips",
"value": [
{
"tripId": 0,
"shareId": "9d9b2fa0-efbf-490e-a5e3-bac8f7d47354",
"description": "Trip from San Francisco to New York City. Nice trip with two friends. It is a 4 days' trip. We actually had a client meeting, but we also took one to go sightseeings in New York.",
"name": "Trip in US",
"budget": 3000,
"startsAt": "2014-01-01T00:00:00Z",
"endsAt": "2014-01-04T00:00:00Z",
]
}
]
}
但是我在解析文件时遇到错误...下面是我的 java 代码
public static void main(String[] args) {
Employee employee = null;
ObjectMapper mapper = new ObjectMapper();
//mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
try {
employee = mapper.readValue(new File("C:/Users/vikram.b.ravi/Desktop/trip.json"),
Employee.class);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(employee);
}
***我遇到的错误
org.codehaus.jackson.JsonParseException: Unexpected character (']' (code 93)): was expecting double-quote to start field name
at [Source: C:\Users\vikram.b.ravi\Desktop\trip.json; line: 12, column: 14]null***
请帮助我如何抑制 JSON 文件中的特殊字符???
最佳答案
您的 json 无效。
您必须删除“endsAt”行末尾的逗号
并且第一个 [
必须删除:
{
"@odata.context": "http://services.odata.org/V4/(S(ssjoqalpf5sovrqt2mkbpj2t))/TripPinServiceRW/$metadata#People('russellwhyte')/Trips",
"value": [
{
"tripId": 0,
"shareId": "9d9b2fa0-efbf-490e-a5e3-bac8f7d47354",
"description": "Trip from San Francisco to New York City. Nice trip with two friends. It is a 4 days' trip. We actually had a client meeting, but we also took one to go sightseeings in New York.",
"name": "Trip in US",
"budget": 3000,
"startsAt": "2014-01-01T00:00:00Z",
"endsAt": "2014-01-04T00:00:00Z"
}
]
}
关于java - 将 JSON 文件解析为 Java 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28068702/