1

我正在解析http://maps.google.com/maps/geo?q=48.209946,11.539421&output=csv。回复是 200,8,“Lerchenstraße 66, 80995 Munich, Germany”。我只显示 CityName,即“Lerchenstraße 66”。但问题是 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);
}

请帮我。提前致谢。

4

1 回答 1

-1

我得到了答案。感谢您的支持和建议。代码是:

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”。

于 2012-11-29T07:01:48.057 回答