19

I'm sending some JSON in an HTTP POST request. Some of the text within the JSON object is supposed to have superscripts.

If I create my string in C# like this:

string s = "here is my superscript: \u00B9";

... it converts the \u00B9 to the actual superscript 1, which breaks my JSON. I want the \u00B9 to show up exactly as I write it in the the string, not as a superscript.

If I add an escape character, then it shows up like: "here is my superscript: \\u00B9"

I don't want to use an escape character, but I also don't want it to be converted to the actual superscript. Is there a way to have C# not do Unicode conversion and leave it as literally: "\u00B9"?

3 Answers 3

32

If I understand your question correctly... add the at symbol (@) before the string to avoid the escape sequences being processed

 string s = @"here is my superscript: \u00B9";

http://msdn.microsoft.com/en-us/library/362314fe(v=vs.80).aspx

0
13

I like @NinjaNye's answer, but the other approach is to use a double-backslash to make it literal. Thus string s = "here is my superscript: \\u00B9"

2

is recommended you encode your string before send to server. You can encode using base64 or URLEncode in client and decode in server side.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.