Objective c 修复NSString中的unicode字符

Objective c 修复NSString中的unicode字符,objective-c,ios,nsstring,character,Objective C,Ios,Nsstring,Character,我从GoogleDirections API得到一个字符串响应,其中包含应该表示不同语言字符的字符。类似于∆߬≥, 与这些类型的角色相似。我认为字符是葡萄牙语,但无论如何,我的字符串包含如下内容: \U00e3o 我不确定这些是零还是O 我不确定这些字符的技术术语是什么,但如何在字符串中修复它们,使它们正确打印 多谢各位 更新: 我已经用正确的术语“unicode”更新了我的问题标题 我检查了几个问题: 还有其他一些。我遵循了答案,但unicode字符不是固定的 更新: 下面是我从GDirec

我从GoogleDirections API得到一个字符串响应,其中包含应该表示不同语言字符的字符。类似于∆߬≥, 与这些类型的角色相似。我认为字符是葡萄牙语,但无论如何,我的字符串包含如下内容:

\U00e3o

我不确定这些是零还是O

我不确定这些字符的技术术语是什么,但如何在字符串中修复它们,使它们正确打印

多谢各位

更新:

我已经用正确的术语“unicode”更新了我的问题标题

我检查了几个问题:

还有其他一些。我遵循了答案,但unicode字符不是固定的

更新:

下面是我从GDirection获取响应的代码

形成请求并获得响应:

        AFHTTPClient *_httpClient = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@"http://maps.googleapis.com/"]];

    [_httpClient registerHTTPOperationClass: [AFJSONRequestOperation class]];

    [_httpClient setDefaultHeader:@"Accept" value:@"application/json"];

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

    [parameters setObject:[NSString stringWithFormat:@"%f,%f", location.coordinate.latitude, location.coordinate.longitude] forKey:@"origin"];

    [parameters setObject:[NSString stringWithFormat:@"%f,%f", location2.coordinate.latitude, location2.coordinate.longitude] forKey:@"destination"];

    [parameters setObject:@"false" forKey:@"sensor"];

    [parameters setObject:@"driving" forKey:@"mode"];

    [parameters setObject:@"metric" forKey: @"units"];

    NSMutableURLRequest *request = [_httpClient requestWithMethod:@"GET" path: @"maps/api/directions/json" parameters:parameters];

    request.cachePolicy = NSURLRequestReloadIgnoringLocalCacheData;

    AFHTTPRequestOperation *operation = [_httpClient HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {

        NSInteger statusCode = operation.response.statusCode;

        if (statusCode == 200) {

            [self parseResponse:responseObject];

        } else {

        }

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) { }];

    [_httpClient enqueueHTTPRequestOperation:operation];
}
正在从响应对象检索信息:

- (void)parseResponse:(NSDictionary *)response {

NSString *status = [response objectForKey: @"status"];

if (![status isEqualToString: @"OK"]) {

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat: @"Google Directions Response Status: %@", status] delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];

    [alert show];
}
else {

NSArray *routes = [response objectForKey:@"routes"];

NSDictionary *routePath = [routes lastObject];

if (routePath) {

    NSString *overviewPolyline = [[routePath objectForKey: @"overview_polyline"] objectForKey:@"points"];

    legs = [routePath valueForKey: @"legs"];

    if (legs) {
/*方向集================================================================================================================================ */

        directionOverview = [[NSMutableDictionary alloc] init];

        NSString *legsDis = [NSString stringWithFormat: @"%@", [[legs valueForKey: @"distance"] valueForKey: @"text"]];

        NSString *kmDistance = [self cutStringToPreference: legsDis];

        if (kmDistance) {

            [directionOverview setObject:kmDistance forKey: @"distance"];

            milesLabel.text = kmDistance;

            milesLabel.font = [UIFont fontWithName:@"interstate" size: 20.0];
        }

        NSString *durationText = [NSString stringWithFormat: @"%@", [[legs valueForKey: @"duration"] valueForKey: @"text"]];

        durationText = [self cutStringToPreference: durationText];

        if (durationText) {

            [directionOverview setObject:durationText forKey: @"duration"];
        }                
            NSString *startAddress = [NSString stringWithFormat: @"%@", [legs valueForKey: @"start_address"]];

            startAddress = [self cutStringToPreference: startAddress];

            NSString *endAddress = [NSString stringWithFormat: @"%@", [legs valueForKey: @"end_address"]];

            endAddress = [self cutStringToPreference: endAddress];

            [directionOverview setObject:startAddress forKey: @"origin"];
            [directionOverview setObject:endAddress forKey: @"destination"];

        NSArray *steps = [legs valueForKey: @"steps"];

        if (steps) {

            instructionArray = [[NSMutableArray alloc] init];
            durationArray = [[NSMutableArray alloc] init];
            distanceArray = [[NSMutableArray alloc] init];

            int number = [[[steps lastObject] valueForKey: @"html_instructions"] count];

            for (int i = 1; i <= number; ++i) {

                    NSString *instruction = [[[steps lastObject] valueForKey: @"html_instructions"] objectAtIndex: i-1];

                    instruction = [self cutStringToPreference: instruction];

                    instruction = [self flattenHTML: instruction];

                    instruction = [self stringByDecodingHTMLEntitiesInString: instruction];

                    [instructionArray addObject: instruction];

                    NSString *distance = [[[[steps lastObject] valueForKey: @"distance"] objectAtIndex: i-1] valueForKey: @"text"];

                    [distanceArray addObject: distance];

                    NSString *duration = [[[[steps lastObject] valueForKey: @"duration"] objectAtIndex: i-1] valueForKey: @"text"];

                    [durationArray addObject: duration];

        }
    }
}

    _path = [self decodePolyLine:overviewPolyline];

    NSInteger numberOfSteps = _path.count;

    CLLocationCoordinate2D coordinates[numberOfSteps];
    for (NSInteger index = 0; index < numberOfSteps; index++) {
        CLLocation *location = [_path objectAtIndex:index];
        CLLocationCoordinate2D coordinate = location.coordinate;

        coordinates[index] = coordinate;
    }

    polyLine = [MKPolyline polylineWithCoordinates:coordinates count:numberOfSteps];
    [self.mapView addOverlay:polyLine];
}

}

}
更新:


如您所见,在标签中,文本包含此类子字符串:S/U00e3o,这是一个具有不受支持字符的单词。我该如何解决这个问题,使unicode变成这样:São

技术术语是。您需要向我们展示更多的代码。请说明如何调用API,返回消息中的类型,以及如何使用特殊字符打印字符串。我使用AFNetworking调用google directions API,我请求JSON响应。字符串响应只是key origin的对象,最具体地说是方向起始位置的原点,我已经将其设置为位于圣保罗。我只是给这个字符串分配了一个标签文本。我已经将我的问题更新为unicode,我还研究了很多关于如何解决这个问题的5个问题,但是没有找到答案。幸运的是,您没有提供@dasblinkenlight要求的信息,所以我们不知道运行的是什么代码,也不知道您为什么认为这是一个问题。
        NSString *overviewAddressText = [NSString stringWithFormat: @"%@ to %@", [directionOverview objectForKey: @"origin"], [directionOverview objectForKey: @"destination"]];

    overviewAddress.text = overviewAddressText;