我foursquare API
用来获取我周围的一些位置,但是当那个地方的名称不是英文时,名称将如下所示:
name = "\U0645\U0633\U062c\U062f \U0627\U0644\U0633\U064a\U062f\U0629 \U0639\U0627\U0626\U0634\U0629 | Aisha Mosque";
我试图将其转换response
为 UTF-8,但没有任何改变。
这是我的代码:
-(void)setUpLocations{
NSURL *url = [NSURL URLWithString: @"https://api.foursquare...."];
NSData *data = [NSData dataWithContentsOfURL:url];
NSError *error = nil;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
NSLog(@"Response: %@",[[[json objectForKey:@"response"]objectForKey:@"groups"]valueForKey:@"items"]);
}
日志结果是:
contact = { }; id = 51712507498ec4e8c5ae9f48; likes = { count = 0; groups = ( ); }; location = { address = Abdoun; cc = JO; city = Amman; country = Jordan; distance = 3819; lat = "31.95406043797281"; lng = "35.88095228186612"; }; name = "\U0645\U0633\U062c\U062f \U0627\U0644\U0633\U064a\U062f\U0629 \U0639\U0627\U0626\U0634\U0629 | Aisha Mosque"; restricted = 1; stats = { checkinsCount = 43; tipCount = 2; usersCount = 23; }; verified = 0; },
有什么建议么 ??
编辑: 这是我从字典中提取数据的方法:
NSDictionary *dic = [[[[json objectForKey:@"response"]objectForKey:@"groups"]valueForKey:@"items"] copy];
namesArray = [[NSArray alloc]initWithArray:[self removeWhiteSpaces:[dic valueForKey:@"name"]]];
-(NSArray *)removeWhiteSpaces:(NSDictionary *)dic{
NSString *str = [NSString stringWithFormat:@"%@",dic];
NSString *str2 = [str stringByReplacingOccurrencesOfString:@"\n" withString:@""];
NSString *secondString = [str2 stringByReplacingOccurrencesOfString:@" " withString:@""];
NSString *thirdString = [secondString stringByReplacingOccurrencesOfString:@"(" withString:@""];
NSString *forthString = [thirdString stringByReplacingOccurrencesOfString:@")" withString:@""];
NSString *fifthString = [forthString stringByReplacingOccurrencesOfString:@"\"" withString:@""];
NSArray *items = [fifthString componentsSeparatedByString:@","];
return items;
}
并且在UITableView
:
cell.textLabel.text = [NSString stringWithFormat:@"Name: %@ ",[namesArray objectAtIndex:indexPath.row] ];
更新
尝试@Martin R 回答后,我得到了相同的结果:
NSDictionary *dic = [[[[json objectForKey:@"response"]objectForKey:@"groups"]valueForKey:@"items"] copy];
NSString *value =[dic valueForKey:@"name"];
NSLog(@"%@", value);
UILabel *lbl = [[UILabel alloc]initWithFrame:self.view.frame];
lbl.numberOfLines = 0;
lbl.text = [NSString stringWithFormat:@"%@",value];;
[self.view addSubview:lbl];
这是结果的图像