I'm getting a json which on deserializing could be of any class say:
Question
Answer
- Comment
So I need to switch based on what class that json belongs to.
Currently I'm using this to deserialize. But the problem is if I use this, I'm premeditating what type I'll receive.
Question question = new JavaScriptSerializer().Deserialize<Question>(payload);
But I want to do this instead:
var jsonType = ParseJson(payload);
switch (jsonType)
{
case Question: {Question question = new JavaScriptSerializer().Deserialize<Question>(payload); break;}
case Answer: ...
case Comment: ...
}