I'm facing this json data:
{
"pagemeta": {
"slug": "/",
"title": "test",
"description": "test"
},
"navigationlinks": {
"links": [{
"navigationlink": {
"name": "Index.",
"url": "/"
}
}]
}
}
And both using HttpRespondeMessage.Content.ReadAsJsonAsync<T>();
or JsonConvert.DeserializeAnonymousType(jsonString, new MyClassToDeserializeInto())
Both parsings seem to function well, except when it comes to the objects inside the array "links"
.
Those do get to become object in the array in class but all data is null
(both name
and url
like in this example).
Am I doing something wrong to don't get the json deserialized correctly?
Following are the classes that I use as the final target object:
HomeData.cs
public sealed class HomeData
{
[JsonProperty("pagemeta")]
public PageMeta PageMeta { get; set; }
[JsonProperty("navigationlinks")]
public NavigationLinks NavigationLinks { get; set; }
}
NavigationLinks.cs
public class NavigationLinks
{
[JsonProperty("links")]
public NavigationLink[] Links { get; set; }
}
NavigationLink.cs
public class NavigationLink
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("url")]
public string Url { get; set; }
}
meanwhile the PageMeta.cs
does the data correctly.