I’ve tried to get some data which contains utf-8 characters from iOS, ended up failing : (
-
JSON data come from Rails app.
render :json => @userssnippet shows below:
{"likes_num":554,"name":"\u62c9\u7f8e\u4eb2\u5386\u8bb0\u00a0","remote_id":63573783,"remote_identifier":"douban"} -
Used both
NSJSONSerializationandSBJsonwith failures. And it seems utf-8 string are modified asname = "\U62c9\U7f8e\U4eb2\U5386\U8bb0\U00a0";(UsingNSLog(@"%@", json)). NSLog(@"%@", [json objectForKey:@"name"])just return nothing, leave no log.- Save the name as
NSString *name, andNSLogremains the same, but print description ofnamewhen debug, the utf-8 sentence appears perfectly. - Tried
[name description], got nothing either.
Please give me some hints to figure out what really happens to my utf-8 sentence.
Thanks in advanced.
UPDATE: Value for other keys works fine, i.e [json objectForKey:@"remote_identifier"] gives douban, only @"name" down for no reason.
Dave
With the help from a colleague of mine, i got over this finally. Here is how:
Actually, there are something i haven’t mentioned in the question that the value of
namecan sometimes benullornil. And with this type of value, the type of this field is set to something related toKFNull, and every access of the data risk in sending aisEqualToString:to NSNull which doesn’t response to that method.And i still don’t understand why
NSLogfailed to print out the non-null data. But i’ve got a solution to the problem.Surprisingly it have no relation with encoding : /