Ios 加载json时,阿拉伯字符串不可读
代码: 有关结果的问题如下:Ios 加载json时,阿拉伯字符串不可读,ios,objective-c,json,character-encoding,arabic-support,Ios,Objective C,Json,Character Encoding,Arabic Support,代码: 有关结果的问题如下: +(id)loadJSONDataFromURL:(NSString *)urlString{ MsgsHelper *msg=[[MsgsHelper alloc]init]; // This function takes the URL of a web service, calls it, and either returns "nil", or a NSDictionary, // describing the JSON data that was re
+(id)loadJSONDataFromURL:(NSString *)urlString{
MsgsHelper *msg=[[MsgsHelper alloc]init];
// This function takes the URL of a web service, calls it, and either returns "nil", or a NSDictionary,
// describing the JSON data that was returned.
NSError *error;
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
// Call the web service, and (if it's successful) store the raw data that it returns
NSURLResponse *response = nil; //
NSData *data = [ NSURLConnection sendSynchronousRequest:request returningResponse: &response error:&error ];
//here we get the respond from NSURLResponse and then we check for the statusCode //1
//200 is ok,, 0 is no internet connection else is server error //2
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;//1
//any warning like this one with integers shuold add the casting (int)
int statCode = (int)[httpResponse statusCode];//2
if(statCode == 200){
if (!data)
{
//NSLog(@"Download Error: %@", error.localizedDescription);
return nil;
}
// Parse the (binary) JSON data from the web service into an NSDictionary object
id dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
if (dictionary == nil) {
//NSLog(@"JSON Error: %@", error);
return nil;
}
return dictionary;
}else if(statCode == 0){
[msg alertStatus:NSLocalizedString(@"No internet", @"Message") :@"" :0 ];
return nil;
}else{
//Server Error
//NSLog(@"Server Error");
[msg alertStatus:NSLocalizedString(@"Server Error", @"Message") :@"" :0 ];
return nil;
}}
可能需要使用数据编码来读取阿拉伯字符串,但如何做到这一点
谢谢,它看起来不错,只需制作一个临时UILabel并将其文本设置为您的文本,您就会看到阿拉伯语。-相信我,我是一名工程师谢谢亲爱的,它正在工作。出于好奇:@ColdSteel我有相同的问题,我设置了texView。text=ArabicValue,但相同的整数是given@iOS开发者,嗨,我已经好几年没接触iOS了,但也许这会有所帮助
results: (
{
"Name" = "\U0633\U0639\U0648\U062f \U0639\U0628\U062f\U0627\U0644\U0639\U0632\U064a\U0632 \U064a\U0646 \U062c\U062f\U064a\U062f";
"location" = CENTER;
}
)