我正在尝试使用 Web 服务,但是当元素名称更改时,更改所有其他...
-(void)callWebService {
_estacionamentoAdd = [[Estacionamento alloc]init];
NSString *url = @"http://urlfromws";
NSMutableURLRequest *request =[[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"GET"];
NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn) {
webData = [[NSMutableData data] retain];
}
else
{
}
}
//什么时候得到response的值
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if(!soapResults)
{
soapResults = [[NSMutableString alloc] init];
}
NSLog(@"stringFound:%@", string);
[soapResults setString:string];
}
//收到响应时
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if(!soapResults)
{
soapResults = [[NSMutableString alloc] init];
}
if( [elementName isEqualToString:@"id"])
{
id = [soapResults intValue];
}
else if( [elementName isEqualToString:@"name"])
{
name = soapResults;
}
else if( [elementName isEqualToString:@"adress"])
{
adress = soapResults;
}
[soapResults setString:@""];
}
当元素名称为“名称或地址”时,id 和名称等于地址
当 elementName 是 id...id = soapResults。好的,但是当 elementName 是 Adress 时,adress=soapResults 并且 id 也会改变。为什么?