Today I ran into a problem: the serialized JSON was corrupted with content that looks like this:
My reaction was puzzlement: why on earth would a straightforward class with properies like Data and Count suddenly start spitting out weird JSON like this?
SO to the Rescue?
Obviously the first port of call was a search on StackOverflow
But we’re not supposed to be using DataContractJsonSerializer, we’ve got WebApi which uses JSON.NET?
Turns out the cause is the SerializableAttribute – because I’d added that to the class, the object result from the WebAPI method got passed to DataContractJsonSerializer.
I had not seen this before because most of the results I had output didn’t have this attribute, even though the base class did. I removed this, and bingo, the results were fixed: