我想在项目中更具体地使用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处理这种情况?
先谢谢