2012-11-09 51 views
0

我有这段代码,我想用编码来阅读阿拉伯语和表情符号。如何使用UTF8编码JSONObjectWithData?

使用JSON

在.H我用两个数组

NSArray *news; 

NSMutableData *data; 

和.M

在viewDidLoad中

NSURL *url = [NSURL URLWithString:@"http://myServer.com/getmessages.php"]; 
NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
[[NSURLConnection alloc] initWithRequest:request delegate:self]; 

,我必须使用这些方法

-(void)connection: (NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{  
    data = [[NSMutableData alloc]init];  
} 

-(void)connection: (NSURLConnection *)connection didReceiveData:(NSData *)theData 
{ 
    [data appendData:theData]; 
} 

-(void)connectionDidFinishLoading: (NSURLConnection *)connection 
{ 

    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 


    news = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil]; 

    if (news == nil || [news count] == 0) { 

     UIAlertView *errorView = [[UIAlertView alloc]initWithTitle:@"Sorry!!" message:@" No News !!" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles: nil]; 
     [errorView show]; 
    } 

    [self.tableView reloadData]; 
} 

-(void)connection: (NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 

    UIAlertView *errorView = [[UIAlertView alloc]initWithTitle:@"Error" message:@"The download could not complete - Plaese make sure           you're connected to either 3G or Wi-Fi" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles: nil]; 
    [errorView show]; 

    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 

} 

和我使用的UITableView

cell.newsLabel.text = [[news objectAtIndex:indexPath.row]objectForKey:@"Content"]; 

什么是阿拉伯语和表情符号的编码?以及如何在此代码中使用编码

回答

0

可以在Unicode6.0或更高版本(UTF8),iOS5或更高版本中使用表情符号。