0

我的 XML 文件有中文字符,它们是 Big-5,如何根据下面的代码将其转换为 UTF-8?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSString *xmlFilepath = [[[NSBundle mainBundle] resourcePath]  stringByAppendingPathComponent:@"Hostels.xml"];


    NSData *xml = [[NSData alloc] initWithContentsOfFile:xmlFilepath];



    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:xml];

    Parser *theParser = [[Parser alloc] initParser];

    [xmlParser setDelegate:theParser];

.......
4

1 回答 1

0

尝试使用这段代码提取Big-5编码的汉字

//-2147481085,  // Traditional Chinese (Big 5)
//-2147481082,  // Traditional Chinese (Big 5 HKSCS)
//-2147482589,  // Traditional Chinese (Windows, DOS)
//-2147483646, //Traditional Chinese (Mac OS)
#define NSBIG5Encoding -2147482589
NSString* content = [NSString stringWithContentsOfFile:fileParh_
                                              encoding:NSBIG5Encoding
                                                 error:nil];
NSData *XMLData = [content dataUsingEncoding:NSUTF8StringEncoding];
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:XMLData];
于 2012-09-24T04:33:50.267 回答