AFJSONRequestOperation与JSON编码为NSISOLatin1StringEncoding崩溃

时间:2013-02-11 17:08:49

标签: iphone ios objective-c json afnetworking

我想在项目中更具体地使用AFNetworking AFJSONRequestOperation以允许轻松的异步调用。我很快尝试使用AFNetworking GitHub Page

中的示例代码
NSURL *url = [NSURL URLWithString:@"https://alpha-api.app.net/stream/0/posts/stream/global"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request 
    success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
        NSLog(@"App.net Global Stream: %@", JSON);
    } 
    failure:nil];
[operation start];

哪个工作正常,但是当我使用MetOffice Datapoint的URL崩溃时,我相信这可能是因为JSON提要的编码类型为NSISOLatin1StringEncoding导致NSJSONSerialization <的问题/ p>

我目前处理此问题的方式是

NSString *string = [NSString stringWithContentsOfURL:kMetOfficeAllSites encoding:NSISOLatin1StringEncoding error:&error];
NSData *metOfficeData = [string dataUsingEncoding:NSUTF8StringEncoding];
id jsonObject = [NSJSONSerialization JSONObjectWithData:metOfficeData options:kNilOptions error:&error]

但是如何使用AFJSONRequestOperation处理这种情况?

先谢谢

0 个答案:

没有答案