Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios WebService不完全目标-C_Ios_Xml Parsing_Webservice Client - Fatal编程技术网

Ios WebService不完全目标-C

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

我正在解析我的应用程序上的webService响应(XML),我意识到并不是所有的答案都被解析(我希望至少还有3个相同的信息块),所以我决定修改我的方法ConnectiondFinishLoading,如下所示:

-(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];
}
我所做的只是:

  • 使用NSString(XMLResponse)并将编码更改为NSISOLATIN1STRINGCODING
  • 通过使用NSString(XMLResponse)一步创建NSData对象,初始化NSXMLParser对象(parse),但现在使用NSUTF8StringEncoding进行编码
  • 试试看,告诉我们进展如何