I received a JSON file, which contains a root element "users", and a list of "user" items.
I'm trying to deserialize the json into a List
of a custom class called User
, but I keep getting a JsonSerializationException
, that it can't cover it.
I tried the following:
Code:
public class User
{
public int ID { get; set; }
public bool Active { get; set; }
public string Name { get; set; }
}
public class Response
{
public List<User> Users { get; set; }
public JObject Exception { get; set; }
}
And -
public Response DeserializeJSON(string json)
{
Response deserialized = JsonConvert.DeserializeObject<Response>(json);
return deserialized;
}
JSON:
{
"Users": {
"User": [
{
"id": "1",
"active": "true",
"name": "Avi"
},
{
"id": "2",
"active": "false",
"name": "Shira"
},
{
"id": "3",
"active": "false",
"name": "Moshe"
},
{
"id": "4",
"active": "false",
"name": "Kobi"
},
{
"id": "5",
"active": "true",
"name": "Yael"
}
]
}
}
Sorry for bad styling!!