After trying to solve it myself and looking for answers on stackoverflow. I need to ask you guys if you can help me.
I dont really know where ir my error, but the fact is that the class I am using to deserialize a json is not being constructed correctly. I get all parameters null.
my class is :
public class Page
{
public int rolePermission;
public string icon;
public string title;
public string url;
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public Page[] children;
[JsonConstructor]
public Page(string rolePermission, string icon, string title, string url, Page[] children)
{
this.rolePermission = int.Parse(rolePermission);
this.icon = icon;
this.title = title;
this.url = url;
this.children = children;
}
}
The json is:
{
"page":
{
"rolePermission":"2",
"icon":"dashboard",
"title":"Dashboard",
"url":"Dashboard"
}
}
The children property could be or not on the json and I think there is the problem.
The json with children would be:
{
"page":
{
"rolePermission":"2",
"icon":"dashboard",
"title":"Dashboard",
"url":"Dashboard",
"children":
{
"page":{
"rolePermission":"2",
"icon":"dashboard",
"title":"Dashboard",
"url":"Dashboard"
}
}
}
}
I wish you can help me guys :)
childrento be an array in the JSON rather than just an object - and I wouldn't expect apagename, either.