2015-09-24 95 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