Ios WebService不完全目标-C
我正在解析我的应用程序上的webService响应(XML),我意识到并不是所有的答案都被解析(我希望至少还有3个相同的信息块),所以我决定修改我的方法ConnectiondFinishLoading,如下所示:Ios WebService不完全目标-C,ios,xml-parsing,webservice-client,Ios,Xml Parsing,Webservice Client,我正在解析我的应用程序上的webService响应(XML),我意识到并不是所有的答案都被解析(我希望至少还有3个相同的信息块),所以我决定修改我的方法ConnectiondFinishLoading,如下所示: -(void) connectionDidFinishLoading:(NSURLConnection *) connection { NSString *XMLResponse = [[NSString alloc]initWithBytes:[webData mutable
-(void) connectionDidFinishLoading:(NSURLConnection *) connection {
NSString *XMLResponse = [[NSString alloc]initWithBytes:[webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
NSLog(@"xml message: %@, data length: %i", XMLResponse, [webData length]);
if ([XMLResponse hasPrefix:@"[ERR]"]){
[[[UIAlertView alloc]initWithTitle:@"Notification"
message:XMLResponse != nil ? [@"there was an error while trying to load service" stringByAppendingString:XMLResponse]: @"there was an error while trying to load service"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil]show];
_transacWebServCompleto = @"FALSE";
return;
}
xmlParser = [[NSXMLParser alloc] initWithData:webData];
[xmlParser setDelegate:self];
[xmlParser setShouldResolveExternalEntities:YES];
[xmlParser parse];
}
当我运行我的应用程序时,我在输出部分得到了这个
xml message: (null), data length: 5516
该表打印正确,但不完整,我的XML显示为null,但由于数据长度的原因,它包含数据,如果有任何帮助,我将不胜感激
提前感谢您的XML可能包含特殊字符,如重音词,请尝试以下方法:
-(void) connectionDidFinishLoading:(NSURLConnection *) connection {
NSString *XMLResponse = [[NSString alloc]initWithBytes:[webData mutableBytes] length:[webData length] encoding:NSISOLatin1StringEncoding];
NSLog(@"xml message: %@, data length: %i", XMLResponse, [webData length]);
if ([XMLResponse hasPrefix:@"[ERR]"]){
[[[UIAlertView alloc]initWithTitle:@"Notification"
message:XMLResponse != nil ? [@"there was an error while trying to load service" stringByAppendingString:XMLResponse]: @"there was an error while trying to load service"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil]show];
_transacWebServCompleto = @"FALSE";
return;
}
xmlParser = [[NSXMLParser alloc] initWithData:[XMLResponse dataUsingEncoding:NSUTF8StringEncoding]];
[xmlParser setDelegate:self];
[xmlParser setShouldResolveExternalEntities:YES];
[xmlParser parse];
}
我所做的只是: