我正在调用 SOAP API ,我收到了 XML 格式的响应,我尝试通过设置 XML >委托。我没有调用委托方法的问题,这里是我调用的API和解析代码。
- (void)viewDidLoad {
[super viewDidLoad];
NSDictionary *dictionary = @{@"mobileuser3":@"loginUser"};
[[WMAPIClient sharedClient] loginAPI:@"/01/wsdl/LoginUserService" withParameters:dictionary withSuccessBlock:^(id responseObject){
NSXMLParser *XMLParser = (NSXMLParser *)responseObject;
[XMLParser setShouldProcessNamespaces:YES];
XMLParser.delegate = self;
[XMLParser parse];
}withFailureBlock:^(NSError *error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error Retrieving Data"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
}];
}
这是解析器委托方法
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
NSString *ele = elementName;
NSLog(@"elementName = %@, qName = %@",elementName,qName);}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
NSLog(@"string = %@", string);
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
NSLog(@"elementName = %@, qName = %@",elementName,qName);
}
- (void) parserDidEndDocument:(NSXMLParser *)parser{
NSLog(@"End");
}
请帮我解决问题......提前致谢
答案 0 :(得分:0)
据我所知,您收到的对象类型存在问题。 NSXMLParser
初始化方法很少,最常见的方法是initWithData
和initWithURL
。
尝试添加这些行以进行修复;
NSString *xmlString = responseObject.responseString;
NSData *xmlData = [xmlString dataUsingEncoding:NSUnicodeStringEncoding];
然后使用initWithData
选项。