I have got json:
{
"_embedded": {
"users": {
"1688416": {
"id": 1688416,
"name": "test"
},
"1688395": {
"id": 1688395,
"name": "test",
},
"1625614": {
"id": 1625614,
"name": "test"
}
}
}
}
I should deserialize it by Newtonsoft.JSON library, but i can't undestand how to?? Object in "users" object can change, and "users" - is not array.
I can just JsonConvert.DeserializeObject(myobject) and take all fields by indexes, but it's stupidly, and i want to deserialize this json to normal object. How to?
UPDATE: code that i use
T is User
public class Response<T>
{
[JsonProperty("_embedded", NullValueHandling = NullValueHandling.Ignore)]
public EmbeddedContent<T> EmbeddedContent { get; set; }
}
public class EmbeddedContent<T>
{
[JsonPropertyNameBasedOnItemClass]
public List<T> Items { get; set; }
}
public class User{
public int id{get;set;}
public string name {get;set;}
}
JsonPropertyNameBasedOnItemClass - work like JsonProperty("users")
and try deserialize:
JsonConvert.DeserializeObject<Response<User>>(...)