Home NSString Decoding
Reply: 0

NSString Decoding

user1148
1#
user1148 Published in April 26, 2018, 1:45 pm

I have a situation, I don't know what causing it.

I have got a string from server like this

NSString *str=@"\\u3060\\u3044\\u3053\\u3093\\u3001\\u5927\\u6839\\n";

I am trying to decode it using the following code..

NSLog(@"%@",[self decodeString:str]);


-(NSString*)decodeString:(NSString *)inputString{
    NSData *utfStringData=[inputString dataUsingEncoding:NSUTF8StringEncoding];
    NSString *output=[[NSString alloc] initWithData:utfStringData encoding:NSNonLossyASCIIStringEncoding];
    return output;
}

I get nil as output.

But when I remove extra "\" from the input string, NSString itself shows the proper wording without even passing into decodeString function, see below

So I decided the replace the extra "\" from input string using following code

inputString=[inputString stringByReplacingOccurrencesOfString:@"\\\\" withString:@"\\"];

Above code doesn't work either.

My question is -> What am I doing wrong? How does it work?

Thanks for Helping.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.242681 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO