将JSON中的UTF8string转换为纯文本iOS?
Iam试图在UITableViewCell中显示JSON列表。 当我parsing我的JSON我可以看到UTF8字符,当我显示UILabels UTF8string显示错误的值。
这是我的JSON文件结构
[{"name":"C\u0103r\u021bile pe fa\u021b\u0103 (Taxi Gratis)","code":"TX7","details":"tertert","costperkm":"ertrete","minimumcost":"tetret","taxicontact":[{"carrier":"ertertert","number":"ert"}],"taxistation":[{"stationname":"terterter","latitude":"tertert","longitude":"rete","details":"terterterter"}],"logo":"","tag":"tertertertert"}]
我试图在我的UILabel中显示这个"name":"C\u0103r\u021bile pe fa\u021b\u0103 (Taxi Gratis)"
,并且显示出这样的“ C?r?ile> pe fa??"
代码我试过了
NSString *correctString = [NSString stringWithCString:[ss cStringUsingEncoding:NSUTF8StringEncoding] encoding:NSUTF8StringEncoding]; NSLog(@"%@",correctString);
请帮我解决这个问题。
我试过这段代码,它运行正确:
NSArray *jsonArray = @[ @{ @"name":@"C\u0103r\u021bile pe fa\u021b\u0103 (Taxi Gratis)", @"code":@"TX7", @"details":@"tertert", @"costperkm":@"ertrete", @"minimumcost":@"tetret", @"taxicontact":@[ @{ @"carrier":@"ertertert", @"number":@"ert" } ], @"taxistation":@[ @{ @"stationname":@"terterter", @"latitude":@"tertert", @"longitude":@"rete", @"details":@"terterterter" } ], @"logo":@"", @"tag":@"tertertertert" } ]; NSDictionary *jsonDict = [jsonArray objectAtIndex:0]; NSString *str = [jsonDict objectForKey:@"name"]; NSString *correctString = [NSString stringWithCString:[str cStringUsingEncoding:NSUTF8StringEncoding] encoding:NSUTF8StringEncoding]; NSLog(@"%@",correctString); UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(20, 200, 280, 40)]; lbl.backgroundColor = [UIColor cyanColor]; lbl.text = correctString; [self.view addSubview:lbl];