我在UIAlertView
中顯示國際字符時遇到問題。iOS上UIAlertView中的國際字符集
我從this URL檢索JSON格式的字符串。
返回的格式正常,它包含正確的字符。
當我嘗試加載它在我的應用程序在UIAlertView
我看到這一點:
什麼是從西班牙,克羅地亞,中國等顯示Unicode字符的正確方法?
更改設置中的默認語言並不能解決問題。
我在UIAlertView
中顯示國際字符時遇到問題。iOS上UIAlertView中的國際字符集
我從this URL檢索JSON格式的字符串。
返回的格式正常,它包含正確的字符。
當我嘗試加載它在我的應用程序在UIAlertView
我看到這一點:
什麼是從西班牙,克羅地亞,中國等顯示Unicode字符的正確方法?
更改設置中的默認語言並不能解決問題。
沒有任何代碼,很難指出你錯在哪裏。下面的代碼工作,我只能假設你正在做的東西特別與編碼數據的果味。
NSData *data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://kancelarijahatipovic.com/translate.php?from=eng&dest=hr&phrase=iron"]] returningResponse:nil error:nil];
NSString *string = [NSString stringWithUTF8String:[data bytes]];
SBJsonParser *parser = [[SBJsonParser alloc] init];
id returnVal = [parser objectWithString:string];
if([returnVal isKindOfClass:[NSDictionary class]]) {
//build string
NSMutableString *alertString = [NSMutableString string];
if([returnVal objectForKey:@"tuc"] != nil) {
NSArray *tucs = [returnVal objectForKey:@"tuc"];
for(id tucObject in tucs) {
if([tucObject isKindOfClass:[NSDictionary class]] && [tucObject objectForKey:@"phrase"] != nil) {
id phraseObject = [tucObject objectForKey:@"phrase"];
if([phraseObject isKindOfClass:[NSDictionary class]] && [phraseObject objectForKey:@"text"] != nil) {
[alertString appendFormat:@"%@\n", [phraseObject objectForKey:@"text"]];
}
}
}
}
if(alertString.length > 0) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"example" message:alertString delegate:nil cancelButtonTitle:@"okay" otherButtonTitles: nil];
[alertView show];
}
}
編輯:SBJsonParser objectWithData:
提供了與上面相同的結果。
這工作,NSString *字符串= [NSString stringWithUTF8String:[數據字節]];做的伎倆,謝謝! – user2274239
你是如何解碼json的? –
我們正在使用sbjsonparser – mirzahat
你可以發佈你的代碼從JSON獲取字符串並將它們分配給UIAlertView? –