我使用 XML 解析器从服务器检索 xml。
我有以下两件事:
NSMutableArray *catalogueList;
Catalogue *currentCatalogue;
目录如下所示:
#import "Catalogue.h"
@implementation Catalogue
@synthesize id_model;
@synthesize name;
@synthesize url;
@end
这段代码也是:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"catalogue"])
{
// Add currentCatalogue to array
[catalogueList addObject: currentCatalogue.url];
}
这很好用,但有一个小问题。当我这样做时:
NSLog(@"Valoare url %@", currentCatalogue.url);
它显示正确的 URL。
但是当我这样做时:
NSLog(@"Valoare url %@", catalogueList);
输出是“链接”。
这根本不正确:我得到的是Coup\U00e9
,而不是Coupé
。请告诉我如何在 catalogueList
中获取带有 é
字符的正确链接。
最佳答案
确保您的 url 属性是数组中的字符串。
@interface Catalogue : NSObject{
NSString *myURL;
}
NSString 不会改变特殊字符,并且应该输出与输入完全相同的内容。以下假设您已经将字符串添加到数组中。
NSLog(@"My URL: %@", [currentCatalogue objectAtIndex:0]);
Ouput: My URL: http://host_server/uploads/modeles_pdf/41_TTRS_Coupé_TTRS_Roadster_Tarifs_20110428.pdf
此外,尝试执行此操作,看看是否会出现相同的错误...
NSString *temp = currentCatalogue.url;
//Check the string
NSLog(@"NSString temp: %@", temp);
//Add it to the array
[catalogueList addObject:temp];
//Assuming object is at index 0, check the object in the array
NSLog(@"My URL: %@", [catalogueList objectAtIndex:0]);
关于iphone - 无法从 NSXMLParser 解码 UTF8 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7441976/