NSXMLParser:如何显示从webservice获得的响应?

时间:2021-10-17 03:09:24

I am using NSXMLParser to parse my data obatained from my webservice. But when I get the data from the server.

我正在使用NSXMLParser来解析我的webservice输出的数据。但是当我从服务器获取数据时。

It gives me Error Code 5.

它给出了错误码5。

I am not able to see the response that comes from the webservice.

我看不到来自webservice的响应。

I use

我使用

 NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:theURL];

But I cannot see the response in console when I write NSLog(@"%@",parser);

但在编写NSLog(@“%@”,解析器)时,我无法在控制台中看到响应;

How can I display the response obtained from my webservice?

如何显示从webservice获得的响应?

2 个解决方案

#1


6  

Data returned from a URL is usually just text. It may also be XML, but you can see the raw response by using the following:

从URL返回的数据通常只是文本。它也可能是XML,但是您可以使用以下命令来查看原始响应:

NSError *error = nil;
NSString *string = [[NSString alloc] initWithContentsOfURL:theURL
                                                  encoding:NSUTF8StringEncoding
                                                     error:&error];
if (error != nil)
{
    NSLog(@"error: %@", error);
}
else
{
    NSLog(@"response: %@", string);
}

#2


0  

With the error code 5 means , your xml was not well formed.
Ans as far as your xml output concerned , you had to implement the nsxmlparserdelegate methods to get the xml parsed check the tutorials on the same topic..

使用错误代码5意味着您的xml格式不佳。就您的xml输出而言,您必须实现nsxmlparserdelegate方法,以获得xml解析检查相同主题的教程。

#1


6  

Data returned from a URL is usually just text. It may also be XML, but you can see the raw response by using the following:

从URL返回的数据通常只是文本。它也可能是XML,但是您可以使用以下命令来查看原始响应:

NSError *error = nil;
NSString *string = [[NSString alloc] initWithContentsOfURL:theURL
                                                  encoding:NSUTF8StringEncoding
                                                     error:&error];
if (error != nil)
{
    NSLog(@"error: %@", error);
}
else
{
    NSLog(@"response: %@", string);
}

#2


0  

With the error code 5 means , your xml was not well formed.
Ans as far as your xml output concerned , you had to implement the nsxmlparserdelegate methods to get the xml parsed check the tutorials on the same topic..

使用错误代码5意味着您的xml格式不佳。就您的xml输出而言,您必须实现nsxmlparserdelegate方法,以获得xml解析检查相同主题的教程。