EN:由於responseObject
是NSXMLParser
例如,你不能把它像串! 您必須實施NSXMLParserDelegate
才能處理xml解析器的進度!
CN:responseObject返回的是NSXMLParser實例,你必須實現NSXMLParserDelegate協議才能處理該xml字符串!騷年! :-)
解決方案1:使用的NSXMLParser來解析器
[manager GET:@"http://openapi.aibang.com/search?app_key=f41c8afccc586de03a99c86097e98ccb&city=%E5%8C%97%E4%BA%AC&q=%E9%A4%90%E9%A6%86" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSXMLParser *XMLParser = (NSXMLParser *)responseObject;
[XMLParser setShouldProcessNamespaces:YES];
XMLParser.delegate = self;
[XMLParser parse];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
解決方案2:使用GDataXML到解析器(很容易)
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager GET:@"http://openapi.aibang.com/search?app_key=f41c8afccc586de03a99c86097e98ccb&city=%E5%8C%97%E4%BA%AC&q=%E9%A4%90%E9%A6%86" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
GDataXMLDocument *doc = [[GDataXMLDocument alloc]initWithData:responseObject encoding:0 error:nil];
NSLog(@"%@",doc.rootElement);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
謝謝。我決定還是儘量用json吧,xml看起來好麻煩。 – 2014-12-04 14:31:55