I happily use the Newtonsoft JSON library.
For example, I would create a JObject
from a .NET object, in this case an instance of Exception (might or might not be a subclass)
if (result is Exception)
var jobjectInstance = JObject.FromObject(result);
now I know the library can deserialize JSON text (i.e. a string) to an object
// only works for text (string)
Exception exception = JsonConvert.DeserializeObject<Exception>(jsontext);
but what I am looking for is:
// now i do already have an JObject instance
Exception exception = jobjectInstance.????
Well it is clear that I can go from on JObject
back to JSON text and then use the deserialize functionality, but that seems backwards to me.
Too late, just in case some one is looking for another way:
According to this post, it's much better now:
Documentation: Convert JSON to a Type
From the documentation I found this
The class definition for
Person
should be compatible to the following:Edit
If you are using a recent version of JSON.net and don't need custom serialization, please see TienDo's answer above (or below if you upvote me :P ), which is more concise.