I'm trying to deserialize the following json object with newtosoft json in c#:
{
"address": "address",
"id": 1,
"latitude": 46.0757062,
"longitude": 18.1975697,
"name": "store name",
"openingHours": [
{
"closeing": "01:00:00",
"opening": "11:00:00",
"weekday": 1
}
]
}
My class looks like this:
[PrimaryKey, JsonProperty("id")]
public int Id { get; }
[JsonProperty("name"), Column("name")]
public string Name { get; }
[JsonProperty("latitude"), Column("latitude")]
public double Latitude { get; }
[JsonProperty("longitude"), Column("longitude")]
public double Longitude { get; }
[JsonProperty("openingHours"), Ignore]
public List<OpeningHours> Openinghours { get; set; }
OpeningHours class:
public class OpeningHours
{
[JsonProperty("weekday")]
public int Day { get; set; }
[JsonProperty("opening")]
public TimeSpan Open { get; set; }
[JsonProperty("closeing")]
public TimeSpan Close { get; set; }
}
Here is how did a try to deserialize:
var result = JsonConvert.DeserializeObject<T>(json); //<-- this one should be the correct
var result = JsonConvert.DeserializeObject<T[]>(json);
var result = JsonConvert.DeserializeObject<List<T>>(json);
Every time i get an error like this:
Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'System.Collections.Generic.Dictionary`2[System.String,xMarksThePub.Model.OpeningHours]' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array. Path 'openingHours', line 1, position 137.
Pub is the name of my class.
I'm dosen't know what am i doing wrong.