Reputation: 77
I want to save special characters/german/swedish character in NSDictionary
and have to post this data to server, but the data saved in the dictionary is converted to some other format as in console output. I am trying to save this string as different typecasts but not getting.
As NSDictionary
's data type is generic, and while sending to POST its sent as in the modified format, I want to save this data in NSDictionary
as it is, so that it can be sent in proper format to server and readable at server-end
My code is
NSString *playerName = @"Lëÿlã Råd Sölvê"; // dummy player name
NSLog(@"playerName: %@",playerName);
NSDictionary *postParameters = @{@"playerName1": playerName,
@"playerName2": [NSString stringWithString:playerName],
@"playerName3": [NSString stringWithUTF8String:[playerName UTF8String]],
@"playerName4": [NSString stringWithCString:[playerName UTF8String] encoding:NSASCIIStringEncoding],
@"playerName5": [[NSString alloc] initWithString:playerName],
@"playerName6": [NSString stringWithFormat:@"%@",playerName]};
NSLog(@"postParameters: %@",postParameters);
and output is
playerName: Lëÿlã Råd Sölvê
postParameters: {
playerName1 = "L\U00eb\U00ffl\U00e3 R\U00e5d S\U00f6lv\U00ea";
playerName2 = "L\U00eb\U00ffl\U00e3 R\U00e5d S\U00f6lv\U00ea";
playerName3 = "L\U00eb\U00ffl\U00e3 R\U00e5d S\U00f6lv\U00ea";
playerName4 = "L\U00c3\U00ab\U00c3\U00bfl\U00c3\U00a3 R\U00c3\U00a5d S\U00c3\U00b6lv\U00c3\U00aa";
playerName5 = "L\U00eb\U00ffl\U00e3 R\U00e5d S\U00f6lv\U00ea";
playerName6 = "L\U00eb\U00ffl\U00e3 R\U00e5d S\U00f6lv\U00ea";
}
How can I achieve this...
Upvotes: 0
Views: 724
Reputation: 53000
There is nothing wrong with your code.
What you are seeing is an artefact of NSLog
and the description
method - the former invokes the latter to obtain the textual representation of an object for output. For NSString
the string is displayed using Unicode. However for NSDictionary
contained strings are displayed using Objective-C Unicode character escape sequences, which have the form '\Uxxxx'
.
To assure yourself all is OK you can use:
for (NSString *key in postParameters)
NSLog(@"%@ -> %@", key, postParameters[key]);
and everything should display fine (except playerName4
where you mess the string up yourself).
Upvotes: 1