I am tryig to access a url which is returning some data which has chinese characters. It returns following response in browser:
{"news":"新聞發佈"}
But when I am trying to read it in my objective c code I am getting nil in nsdata. Following is my objective c code:
NSString *final_url = [NSString stringWithFormat:@"http://xx.xxx.xx.xx:xxxx/iph1/NewsAction.do?service=NEWSNOTIF&lang=2&uid=xxxxxxx"];
final_url = [final_url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:final_url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0];
NSURLResponse *response;
NSError *error = [[NSError alloc] init];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *strResponse = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSData *objectData = [strResponse dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:objectData
options:NSJSONReadingMutableContainers
error:&error];
NSLog(@"json %@",json);
Can someone please help me?
Thanks in advance
Pankaj
0 comments:
Post a Comment