I am trying to Deserialize a Json Object into Dynamic List by order, so I have:
Json:
string json = "{'elements':[
{'EntityA':[
{'name ':'Jhon'}
],
'EntityB':[
{'title' : 'car'}
],
'EntityB':[
{'title':'aaa'}
],
'EntityA':[
{'name' : 'Alice'}
]]}";
.NET Classes Base Classes:
public interface EntitysInterface{}
public class EntityA: EntitysInterface
{
public string name { get; set; }
}
public class EntityB: EntitysInterface
{
public string title { get; set; }
}
public class Entitys
{
public List<EntitysInterface> elements { get; set; } //EntityA, EntityB,...
public Entitys()
{
}
}
My DeserializeObject Dificult:
Entitys listFinaly = JsonConvert.DeserializeObject<Entitys>(json);
Exception "Type is an interface or abstract class and cannot be instantiated. :( "
JsonConvertwouldn't have thrown exception while parsing your json string