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"?
A Python 2 Unicode literal ( u'some text' ) is a different type of Python object from a python byte string ( 'some text' ). It's like using \t versus \T ; the former has meaning in python literals (it's interpreted as a tab character), the latter just means a backslash and a capital T (two characters).
To summarize the previous section: a Unicode string is a sequence of code points, which are numbers from 0 through 0x10FFFF (1,114,111 decimal). This sequence of code points needs to be represented in memory as a set of code units, and code units are then mapped to 8-bit bytes.
A string literal is a sequence of zero or more characters enclosed within single quotation marks. The following are examples of string literals: 'Hello, world!' '10-NOV-91' 'He said, "Take it or leave it."'
A "string literal" is a sequence of characters from the source character set enclosed in double quotation marks (" "). String literals are used to represent a sequence of characters which, taken together, form a null-terminated string.
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
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"
is recommended you encode your string before send to server. You can encode using base64 or URLEncode in client and decode in server side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With