Handle UTF-8 correctly in JSON on iOS

I get some JSON that has weird UTF-8 strings. For instance:

{
  "title": "It\U2019s The End";
}

What is the best way to process this data so that it can be represented in a readable way? I would like to convert this \ U2019 to the quotation mark that it should represent.

Edit: Suppose I parse a string in NSString * jsonResult

Edit 2: I get JSON through AFNetworking :

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    NSString* jsonResult = [JSON valueForKeyPath:@"title"];
} failure:nil];
+5
source share
1 answer

Update:

, AFJSONRequestOperation NSJSONSerialization . , , JSON ( , ;, U U. .


, JSON . JSON JSON, .

. JSON, , , , U u; JSON

NSString* str = @"{\"title\": \"It\\u2019s The End\"}";

NSError *error = nil;
NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *rootDictionary = [NSJSONSerialization JSONObjectWithData:data
                                                               options:0
                                                                 error:&error];
if (error) {
    // Handle an error in the parsing
}
else {
    NSString *title = [rootDictionary objectForKey:@"title"];
    NSLog(@"%@", title); //Prints "It’s The End"
}
+5

All Articles