Remove double curly brackets from JObject that have been added during deserialization

Is this causing a problem or are you just curious? I had the same issue when I was sending data as the type “object” inside another a container class. The container itself was being deserialized properly but the object inside wasn’t. I thought it wasn’t deserializing it because of the double curly braces. In reality, it seems that may just be how JObjects look. The real reason was probably because I had turned off the setting where it sent the type information and since I was deserializing to “object” it couldn’t possibly know what the type from a string alone.

Either way, I noticed if you did “.ToString()” on it then the double curly braces would disappear. This meant I was able to solve my issue by simply doing:

var someType = JsonConvert.DeserializeObject<SomeType>(jObject.ToString());

I’m not sure if this is a bug or not but my guess is that it’s simply an internal implementation detail and that’s why they have it ‘fixed’ when you “.ToString()”.

Leave a Comment

tech