I have problem how do it nicely.
I have string with JSON and want change it to class.
I know I can use this code:
var json = JsonConvert.DeserializeObject<MyClass>(stringJson);
The problem is I have a few classes and don't know how to nicely select what class should be used.
I know one way to do it, but I think it is nasty. E.g.:
try
{
var json = JsonConvert.DeserializeObject<MyClass1>(stringJson);
}
catch()
{}
try
{
var json = JsonConvert.DeserializeObject<MyClass2>(stringJson);
}
catch()
{}
Is there another why to do it?
Edit:
I have 8-10 different versions of what I can get and in all version I know how it will be look (number of version can change).