I'm running into an odd issue and from looking around I can't seem to find any explanation for what's happening.
I'm trying to serialize some data to JSON in C# as follows:
var transactionJson = new JavaScriptSerializer().Serialize(remoteData);
Most of the time this works, but once in a while there is a question mark character injected into the resulting JSON.
and here is the corresponding JSON that gets generated (note the leading "?" added into the ProvinceCode value):
"Addresses": [{
"City": "Edmonton",
"Confidential": null,
"Country": null,
"CountryCode": "CA",
"Line1": "123 Test Dr.",
"Line2": null,
"Line3": null,
"Line4": null,
"PostalCode": "T5K1P4",
"Province": null,
"ProvinceCode": "?ALBERTA",
"Type": null,
"TypeCode": "H"
}],
Does anyone have idea why that extra character is being injected into the value? Looking at the raw data, I'm not seeing any special characters in that field and if I manually retype the value while in debugging mode everything works fine.
I took a look at the char array and it appears that there is a Byte Order Mark character coming through in that string.
That char was being serialized as a "?".
Thanks to @poke for the troubleshooting suggestion.