I got a JSON
data like below and the FlightSegment
object type seems one of the Array
and the other one is not.
When I create an object as FlightSegment[]
, i am getting this error :
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'WA_2_0_RS.FlightSegment[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]
) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>
) that can be deserialized from a JSON object. JsonObjectAttribute
can also be added to the type to force it to deserialize from a JSON object.
What it should be as c# class?
{
"FlightSegment": {
"DepartureAirport": {
"LocationCode": "ESB"
},
"Ticket": "eTicket",
"ArrivalAirport": {
"LocationCode": "ADB"
},
"DateChangeNbr": false,
"StopQuantity": "0",
"CodeshareInd": false,
"Equipment": {
"Value": "UNKNOWN_PLANE",
"AirEquipType": "***"
},
"DepartureDateTime": "2020-12-22T20:10:00.000+03:00",
"ArrivalDateTime": "2020-12-22T21:30:00.000+03:00",
"FlightNumber": "****",
"OperatingAirline": {
"CompanyShortName": "**"
},
"JourneyDuration": "P0DT1H20M0.000S"
}
}, {
"FlightSegment": [{
"DepartureAirport": {
"LocationCode": "ESB"
},
"Ticket": "eTicket",
"ArrivalAirport": {
"LocationCode": "SAW"
},
"DateChangeNbr": false,
"StopQuantity": "0",
"GroundDuration": "P0DT0H45M0.000S",
"CodeshareInd": false,
"Equipment": {
"Value": "A320-200",
"AirEquipType": "320"
},
"DepartureDateTime": "2020-12-22T12:05:00.000+03:00",
"ArrivalDateTime": "2020-12-22T13:10:00.000+03:00",
"FlightNumber": "****",
"OperatingAirline": {
"CompanyShortName": "**"
},
"JourneyDuration": "P0DT1H5M0.000S"
}, {
"DepartureAirport": {
"LocationCode": "SAW"
},
"Ticket": "eTicket",
"ArrivalAirport": {
"LocationCode": "ADB"
},
"DateChangeNbr": false,
"StopQuantity": "0",
"CodeshareInd": false,
"Equipment": {
"Value": "UNKNOWN_PLANE",
"AirEquipType": "73D"
},
"DepartureDateTime": "2020-12-22T13:55:00.000+03:00",
"ArrivalDateTime": "2020-12-22T15:00:00.000+03:00",
"FlightNumber": "****",
"OperatingAirline": {
"CompanyShortName": "**"
},
"JourneyDuration": "P0DT1H5M0.000S"
}
]
}