使用ASIHttpRequest编码问题

Pau*_*len 2 iphone encoding plist asihttprequest ios4

我有ASIHttpRequest的编码问题.当我得到一个URL时,除了一点编码问题外,数据会被完美地返回.

这是我的代码:

- (void)fetchGamesForCategory
{
    NSString *url_string = [[NSString alloc] initWithFormat:url_match, theCategory._id];

    NSURL *url = [NSURL URLWithString:url_string];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request startSynchronous];

    NSError *error = [request error];
    if (!error) {
        NSString *response = [request responseString];

        NSLog(@"response: %@", response);

        NSData *data = [response dataUsingEncoding:NSUTF8StringEncoding];

        NSString *errorDesc = nil;
        NSPropertyListFormat format;
        NSDictionary * dict = (NSDictionary*)[NSPropertyListSerialization
                                              propertyListFromData:data
                                              mutabilityOption:NSPropertyListMutableContainersAndLeaves
                                              format:&format
                                              errorDescription:&errorDesc];

        NSDictionary *categoryListPathDictionary = [[NSDictionary alloc] initWithDictionary:dict];

        categoryMatchList *categoryMatchListFile = [[[categoryMatchList alloc] initWithDictionary:categoryListPathDictionary] retain];
        matchArray = [categoryMatchListFile getMatchListXmlSet];

        [self loadPage];
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的结果:

2010-09-28 21:49:35.970 oddsApp[46429:190f] response: <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist>
    <dict>
        <key>matches</key>
        <array>
            <dict>
                <key>name</key>
                <string>Gais - Häcken</string>
                <key>date</key>
                <string>2010-09-29 18:00</string>
                <key>id</key>
                <string>156</string>
                <key>odds</key>
                <dict>
                    <key>1</key>
                    <string>2.6</string>
                    <key>X</key>
                    <string>3.28</string>
                    <key>2</key>
                    <string>2.862</string>
                </dict>
            </dict>
        </array>
    </dict>
</plist>
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,编码被搞砸了<string>Gais - Häcken</string>,尽管在浏览器中显示页面时它是正确的: FireFox截图

有人知道什么是错的吗?

Kri*_*kel 8

如果您不首先将响应转换为字符串,该怎么办?

NSData *data = request.responseData;
Run Code Online (Sandbox Code Playgroud)