Hi I am developing web application in c#. I have one JSON object. I am trying to de-serialize the object as below. Below is my result.
[ {
"id": "ce053195-ae48-4457-bb88-6ca32f236bd1",
"model": {
"objectId": [
"c760d95e-3fcb-43d1-a7db-111d3384ecbc"
],
"name": [
"Device1-Configuration"
]
},
"childs": 0,
"access": 0,
"allow": 0
},
{
"id": "42ad8eb6-9f35-447c-8ea0-e1346dee410c",
"model": {
"objectId": [
"c760d95e-3fcb-43d1-a7db-111d3384ecbc"
],
"name": [
"Device1-DeviceModel"
]
},
"childs": 1,
"access": 0,
"allow": 0
}
]
Below are my models.
public partial class Resource
{
public System.Guid Id { get; set; }
public Models Model { get; set; }
public bool Selected { get; set; }
public bool hasChildren { get; set; }
public bool IsAllowed { get; set; }
}
Below is my model class.
public partial class Models
{
public List<string> Name { get; set; }
}
I am trying to assign name array from the models.
foreach (JObject singScopeRes in result)
{
var permission = new Rbac.BusinessEntities.V2.Resource();
permission.Id = new Guid(singScopeRes["id"].ToString());
permission.Model = new Rbac.BusinessEntities.V2.Models()
{
Name= singScopeRes["model"]["name"][0]
};
}
This is throwing error saying:
cannot implicit convert type newtonsoft.json.linq.jtoken to system.generic.list
Can someone help me to fix this issue?