2015-09-24 73 views
0

Iam尝试在UITableViewCell中显示JSON列表。 当我解析我的JSON时,我可以看到UTF8字符,当我显示UILabels时,UTF8字符串显示错误的值。将JSON中的UTF8字符串转换为纯文本iOS?

这是我的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); 

请帮助我为此得到解决办法。

+0

什么是 “纯文本”?你想如何显示字符串? –

回答

1

我想这个代码,它运行正确:

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

enter image description here

+0

正在检查这个 – Bangalore

+0

cool dude now working now – Bangalore