How to deserialize json to multiple types dynamically in c# [duplicate]

This question already has an answer here:

I have a json string like below :

{
“error” : “xxxx” ,
“data” : int type or {…other complex json object}
}

I don’t know when return int or other json string from data field , and how to deserialize this ?

when type of data is object or dynamic , the real deserialized type of data is int or Dictionary using JavaScriptSerializer.Deserialize(string json).

the real deserialized type of data is Int64 or JContainer when using Json.Net.

is there a elegance way to solve this ? I don’t think reflection is a good way.