0

我有一些文本在 UITextView 中没有正确显示。“é”、“ç”和“ñ”等...都显示如下:

在此处输入图像描述

文本来自服务器,在 Web 浏览器中查看时显示良好。

想知道如何解决这个问题。谢谢你的帮助。

这是代码:

  // the deal id is passed from the offersvc table selected item and into the url
  // dealID is 1020414

    NSString *jsonDealString = [NSString stringWithFormat:@"http://api.**********.net/v1/public/details?id=%@&yd.key=******", dealId];

    NSLog(@"jsondealstring is %@", jsonDealString);

   // NSLog(@"deal id is %@",dealId);

    // Download JSON
    NSString *jsonString = [NSString
                            stringWithContentsOfURL:[NSURL URLWithString:jsonDealString]
                            encoding:NSStringEncodingConversionAllowLossy
                            error:nil];

    // Create parser for the api
    SBJSON *parser = [[SBJSON alloc] init];
    NSDictionary *results = [parser objectWithString:jsonString error:nil];

    [self setDisplayItems:[results objectForKey:@"results"]];

    NSDictionary *item = (NSDictionary *)[displayItems objectAtIndex:0];

//    NSLog(@"item from details is %@", item);

    // set the labels and text views. 

    link = [item objectForKey:@"link"];
    catStr = [item objectForKey:@"cat"];
    vendorStr = [item objectForKey:@"vendor"];
    titleStr = [item objectForKey:@"main_tag"];
4

1 回答 1

1

You need to set the UTF-8 encoding.

EDIT in response of the modified question

Simply add NSUTF8StringEncoding like follows

NSString *jsonString = [NSString
                        stringWithContentsOfURL:[NSURL URLWithString:jsonDealString]
                        encoding:NSStringEncodingConversionAllowLossy|NSUTF8StringEncoding
                        error:nil];
于 2012-12-28T16:48:10.230 回答