我正在使用 NSXML Parser 在我的 iPhone 应用程序中进行解析。现在一切正常,除非数据是法语。
例如,来自服务器的数据以Ch\u00e9rie FM
.
现在在方法的string
参数下foundCharacters
,我只得到字符串,因为 'Ch' 其余字符没有出现。所以最后我的字符串被截断为 'Ch' 而不是整个Cherie fm
可以做些什么?
代码:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
{
if (appDelegate.objPlayer.fromFlickrorRecommend == TRUE)
{
if([elementName isEqualToString:@"outline"] && [[attributeDict valueForKey:@"text"] isEqualToString:@"You may also like"])
{
flagCheck = 1;
}
else if ([elementName isEqualToString:@"outline"] && [[attributeDict valueForKey:@"text"] isEqualToString:@"Genres"])
{
flagCheck = 0;
}
if (flagCheck == 1 && [elementName isEqualToString:@"outline"])
{
if([[attributeDict valueForKey:@"type"] isEqualToString:@"audio"])
{
[appDelegate.objPlayer.recommendDataArray addObject:attributeDict];
}
}
}
else
{
if ([elementName isEqualToString:@"location"])
{
flagCheck = 2;
}
else if ([elementName isEqualToString:@"url"])
{
flagCheck = 3;
}
else if ([elementName isEqualToString:@"name"])
{
flagCheck = 4;
}
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if (flagCheck == 2)
{
flagCheck = -1;
appDelegate.objPlayer.flickrCity = string;
}
else if(flagCheck == 3)
{
flagCheck = -1;
appDelegate.objPlayer.stationURL = string;
}
else if(flagCheck == 4)
{
flagCheck = -1;
appDelegate.playStationName = string;
}
//else if(flagCheck == 0) // change
// {
// appDelegate.playStationName = string;
// }
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
//if (flagCheck == 1 && [elementName isEqualToString:@"outline"])
// {
// [appDelegate.objPlayer.recommendDataArray addObject:dataDictionary];
// dataDictionary = nil;
// [dataDictionary release];
// }
}