1

Google Directions API から、別の言語の文字を表すはずの文字を含む文字列応答を取得しています。△β¬≧に似た、これらのタイプの文字に似ています。文字はポルトガル語だと思いますが、とにかく私の文字列には次のように含まれています:

\U00e3o

(それらがゼロか「O」かはわかりません)

これらの文字の専門用語が何であるかはわかりませんが、正しく印刷されるように文字列で修正するにはどうすればよいですか。

ありがとうございました

アップデート:

質問のタイトルを正しい用語「ユニコード」で更新しました。

私はいくつかの質問をチェックしました:

NSString Unicode 表示

iPhone の NSString で Unicode 文字を検出する

iOS HTML Unicode から NSString へ?

そして、他にもいくつか。回答に従いましたが、ユニコード文字が固定されていません。

アップデート:

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];
}

}

}

ラベルにテキストを表示する:

        NSString *overviewAddressText = [NSString stringWithFormat: @"%@ to %@", [directionOverview objectForKey: @"origin"], [directionOverview objectForKey: @"destination"]];

    overviewAddress.text = overviewAddressText;

アップデート:

ラベルのイメージ

ご覧のとおり、ラベルのテキストにS/U00e3oは、サポートされていない文字を含む単語である、次のような部分文字列が含まれています。ユニコードが次のようになるように修正するにはどうすればよいですか: São

4

0 に答える 0