0

I need to post Unicode characters to a database. The database I am using receives a NSDictionary and stores that as a JSONObject.

The dictionary is created like:

NSMutableDictionary *messageDictionary = [[NSMutableDictionary alloc] init ];

[messageDictionary setObject:@"message" forKey:@"type"];
[messageDictionary setObject:@"È ê ü à ã" forKey:@"message"];

The database then stores the result as:

{
    type = message;
    message = \"\\U00c8 \\U00ea \\U00fc \\U00e0 \\U00e3\";
}

if I post just the string outside of the dictionary the database stores:

{
    message = È ê ü à ã
}

How do I prevent the NSDictionary from editing these characters and storing them the same way they are entered into a Text View. The same goes for when entering Emoji's into a Text View and sending that. The response I need stored is:

{
    type = messages;
    message = "È ê ü à ã";
}
George Grover
  • 1,134
  • 2
  • 10
  • 17

1 Answers1

1

Conversion from @"È ê ü à ã" to @"\U00c8 \U00ea \U00fc \U00e0 \U00e3" is not something NSDictionary does, so I would assume this is done by the JSON encoder.

I would expect the JSON decoder to put them back to their original form, so the answer is to use a good JSON decoder (by "good" I mean "one that works").

To quote an answer to this question:

2.5. Strings

The representation of strings is similar to conventions used in the C family of programming languages. A string begins and ends with quotation marks. All Unicode characters may be placed within the quotation marks except for the characters that must be escaped: quotation mark, reverse solidus, and the control characters (U+0000 through U+001F).

Any character may be escaped.

Community
  • 1
  • 1
trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • I had misquoted the NSLog with the Server Response, sorry. Updated my question with the stored message with escaped strings. So this would be a server side problem that is changing the characters and is irrelevant of the NSDictionary? If I post just the textview text instead of dictionary I store `È ê ü à ã` – George Grover Nov 12 '14 at 11:28
  • @GeorgeGrover Yes. The server side JSON decoder is broken. – trojanfoe Nov 12 '14 at 11:32