我有以下由web api返回的json,但是在尝试解析它时出现以下错误:这不是json数组。这不是一个json数组 - json被web api返回
{
"$id": "1",
"updateTime": "2013-12-10T12:28:26.6533786+00:00",
"user": {
"$id": "2",
"CompanyID": 1,
"username": "test",
"Firstname": "test",
"Lastname": "ing"
},
"Vehicles": {
"$id": "3",
"$values": [
{
"$id": "4",
"VehicleID": 1,
"CompanyID": 1,
"VehicleReg": "123",
"VehicleTypeID": 1,
"VehicleDescription": ""
},
{
"$id": "5",
"VehicleID": 4,
"CompanyID": 1,
"VehicleReg": "456",
"VehicleTypeID": 2,
"VehicleDescription": ""
},
{
"$id": "6",
"VehicleID": 7,
"CompanyID": 1,
"VehicleReg": "789",
"VehicleTypeID": 3,
"VehicleDescription": ""
}
]
},
"VehicleTypes": {
"$id": "7",
"$values": [
{
"$id": "8",
"VehicleTypeID": 1,
"VehicleType": "First Test Type",
"CompanyID": 1
},
{
"$id": "9",
"VehicleTypeID": 2,
"VehicleType": "Second Test Type",
"CompanyID": 1
},
{
"$id": "10",
"VehicleTypeID": 3,
"VehicleType": "Third Test Type",
"CompanyID": 1
}
]
},
"Questions": {
"$id": "11",
"$values": [
{
"$id": "12",
"QuestionID": 1,
"SectionID": 1,
"CompanyID": 1,
"Question": "Question 1"
},
{
"$id": "13",
"QuestionID": 2,
"SectionID": 1,
"CompanyID": 1,
"Question": "Question 2"
},
{
"$id": "14",
"QuestionID": 3,
"SectionID": 1,
"CompanyID": 1,
"Question": "Question 3"
}
]
},
"QuestionSections": {
"$id": "15",
"$values": [
{
"$id": "16",
"SectionID": 1,
"CompanyID": 1,
"SectionName": "Section 1"
}
]
}
}
我已经通过解析器把这个和它说这是有效的JSON。
我试图解析汽车在JSON像这样:
Gson gsonv = new Gson();
JsonParser parser = new JsonParser();
JsonArray Jarray = (JsonArray)parser.parse(reader).getAsJsonArray();
ArrayList<VehicleEntity> lcs = new ArrayList<VehicleEntity>();
for(JsonElement obj : Jarray)
{
VehicleEntity v = gsonv.fromJson(obj , VehicleEntity.class);
lcs.add(v);
Log.d(TAG, "Vehicles: " + v.VehicleID);
}
我VehicleEntity属性在JSON车辆部分匹配。
我在这里正确的道路上,或者它是由Web API返回的JSON的问题?
由于 保罗
我从来没有使用GSON所以可能是我错了,但你有第一个点头是不是一个JSON数组,实际上没有根元素是jsonarrays –