使用向 iPhone 返回多个值的 Web 服务
我正在构建一个调用 Web 服务的 iPhone 应用程序,该应用程序返回单个值和多个值。
<soap:Body>
<VerifyAccNoResponse xmlns="http://tempuri.org/">
<VerifyAccNoRes>boolean</VerifyAccNoRes>
</VerifyAccNoResponse>
</soap:Body>
我正在使用下面的代码来处理 Xcode 内返回的单个值。
//---when the start of an element is found---
-(void) parser:(NSXMLParser *) parser
didStartElement:(NSString *) elementName
namespaceURI:(NSString *) namespaceURI
qualifiedName:(NSString *) qName
attributes:(NSDictionary *) attributeDict {
if( [elementName isEqualToString:@"VerifyAccNoRes"])
{
if (!soapResults)
{
soapResults = [[NSMutableString alloc] init];
}
elementFound = YES;
}
}
-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string
{
if (elementFound)
{
[soapResults appendString: string];
}
}
//---when the end of element is found---
-(void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"VerifyAccNoRes"])
{
NSLog(soapResults);
if([soapResults isEqualToString:@"false"]){
_result=@"Invalid username or password";}
else {
_result=@"Valid";
}
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Message"
message:_result
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
[soapResults setString:@""];
elementFound = FALSE;
}
}
从 web 服务返回的值作为多值是
<soap:Body>
<GetAccResultResponse xmlns="http://tempuri.org/">
<GetAccoResultRes>
<Error_desc>string</Error_desc>
<Result>
<TAccRes>
<Acc_ID>int</Acc_ID>
<Acc_Name>string</Acc_Name>
</TAccRes>
<TAccRes>
<Acc_ID>int</Acc_ID>
<Acc_Name>string</Acc_Name>
</TAccRes>
</Result>
</GetAccoResultRes>
</GetAccResultResponse>
</soap:Body>
如何在 Xcode 内使用这些值?
BR
I'm building an iPhone application calling webservice that return single and multi values.
<soap:Body>
<VerifyAccNoResponse xmlns="http://tempuri.org/">
<VerifyAccNoRes>boolean</VerifyAccNoRes>
</VerifyAccNoResponse>
</soap:Body>
I'm using the bellow code to work with single value returned inside Xcode
//---when the start of an element is found---
-(void) parser:(NSXMLParser *) parser
didStartElement:(NSString *) elementName
namespaceURI:(NSString *) namespaceURI
qualifiedName:(NSString *) qName
attributes:(NSDictionary *) attributeDict {
if( [elementName isEqualToString:@"VerifyAccNoRes"])
{
if (!soapResults)
{
soapResults = [[NSMutableString alloc] init];
}
elementFound = YES;
}
}
-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string
{
if (elementFound)
{
[soapResults appendString: string];
}
}
//---when the end of element is found---
-(void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"VerifyAccNoRes"])
{
NSLog(soapResults);
if([soapResults isEqualToString:@"false"]){
_result=@"Invalid username or password";}
else {
_result=@"Valid";
}
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Message"
message:_result
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
[soapResults setString:@""];
elementFound = FALSE;
}
}
The returned value from the webservice as amulti values is
<soap:Body>
<GetAccResultResponse xmlns="http://tempuri.org/">
<GetAccoResultRes>
<Error_desc>string</Error_desc>
<Result>
<TAccRes>
<Acc_ID>int</Acc_ID>
<Acc_Name>string</Acc_Name>
</TAccRes>
<TAccRes>
<Acc_ID>int</Acc_ID>
<Acc_Name>string</Acc_Name>
</TAccRes>
</Result>
</GetAccoResultRes>
</GetAccResultResponse>
</soap:Body>
How can I working with these value inside Xcode ?
B.R
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论