1

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.

Here's a screenshot of a portion of the data going in

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.

dbc
  • 104,963
  • 20
  • 228
  • 340
jrrafols
  • 61
  • 3
  • 6
    Maybe there is an invisible character (for the debugger invisible but visible to the text editor—but unknown to the font hence the question mark) at the beginning of the string. Maybe you should check the string explicitly in the debugger by using `ToCharArray`. – poke Mar 11 '16 at 23:48

1 Answers1

1

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.

jrrafols
  • 61
  • 3