我正在解析http://maps.google.com/maps/geo?q=48.209946,11.539421&output=csv。响应为200,8,“Lerchenstraße66,80995 Munich,Germany”。我只显示CityName,即“Lerchenstraße66”。但是问题是CityName字符串具有Unicode字符,并且在视图中显示为“ Lerchenstra \ U00dfe66”。输出应类似于“ Lerchenstrasse”或“Lerchenstraße”。
-(void) httpDataDidFinishLoadingWithData:(NSData *)theData {
m_activityLoaded=NO;
temp=[[NSString alloc] initWithData:[dataLoader httpData] encoding:NSUTF8StringEncoding];
NSArray *listItems = [temp componentsSeparatedByString:@","];
NSArray *tempCountryArray = [[listItems objectAtIndex:[listItems count]-3] componentsSeparatedByString:@"\""];
NSString *string = [NSString stringWithFormat:@"%@", tempCountryArray];
NSString *strTe=[[[[string
stringByReplacingOccurrencesOfString:@"(" withString:@""]
stringByReplacingOccurrencesOfString:@")" withString:@""]
stringByReplacingOccurrencesOfString:@" " withString:@""]
stringByReplacingOccurrencesOfString:@"\"" withString:@"" ];
self.cityNameString = strTe;
NSLog(@"CITY NAME IS : %@", strTe);
}
请帮我。提前致谢。
最佳答案
我得到了答案。感谢您的支持和建议。代码是:
NSString* esc1 = [strTe stringByReplacingOccurrencesOfString:@"\\u" withString:@"\\U"];
NSString* esc2 = [esc1 stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
NSString* quoted = [[@"\"" stringByAppendingString:esc2] stringByAppendingString:@"\""];
NSData* data = [quoted dataUsingEncoding:NSUTF8StringEncoding];
NSString* unesc = [NSPropertyListSerialization propertyListFromData:data
mutabilityOption:NSPropertyListImmutable format:NULL
errorDescription:NULL];
assert([unesc isKindOfClass:[NSString class]]);
NSLog(@"Output = %@", unesc);
输出为“Lerchenstraße66”。