My problem is that I'm getting this error
"Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.List`1[api.Controllers.Journey]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly" ... When I try to serialize my API json response.
The API return something like this:
{
"Transport": [
{
"$id": "6",
"SourceID": "1",
"Context": "1",
"Id": "AMADEUS#1",
"Provider": null,
"Journey": {
"SourceID": "R1G0S0",
"Duration": "42000",
"Id": "5b6db9c6bfac4"
}
},
{
"$id": "7",
"SourceID": "1",
"Context": "1",
"Id": "AMADEUS#1",
"Provider": null,
"Journey": [
{
"SourceID": "R1G0S0",
"Duration": "42000",
"Id": "5b6db9c6bfac4"
},
{
"SourceID": "R1G0S1",
"Duration": "42000",
"Id": "5b6db9c6bsac4"
}
]
}
]
}
The Journey field is an JObject at first result, but is an JArray on second...
And I'm getting the error when I deserialize:
Transport Transport = JsonConvert.DeserializeObject<Transport>(json_response);
My class properties:
public class Transport{
public string SourceID { get; set; }
public string Context { get; set; }
public string Id { get; set; }
public ProviderOD Provider { get; set; }
public Journey[] Journey { get; set; }
public PriceOD Price { get; set; }
}
public class Journey
{
public string Id { get; set; }
public string SourceID { get; set; }
public string Duration { get; set; }
}
What should I do, to set Journey[ ] or Journey dynamically ??
Thanks in advance ...