IOS访问webserver接口

   

接口调用参数只能是字符串格式,返回格式支持3种(字符串,数组,DataSet)

需要引用第三方库,包含(DataSet,PlatServinceDataParser,WebserviceCommon,WebServiceHelper,XMLArrayParser,XMLDataSetParser,XMLResultParser)

程序中引用2个即可

#import "WebServiceCommon.h"

#import"DataSet.h"

 

- (void)getwebserver

{

   WebServiceCommon *webService=[[WebServiceCommonalloc] init];

    

    //方法一,取返回字符串

   NSString *result= [webServicegetResultWithURL:@"http://116.6.52.27:91/webservice/caskaforescService.asmx"xmlNS:nilmethod:@"GetCarTypeTree"pars:nil];

    NSLog(@"%@",result);

    [result release];

    //带参数传值调用方法

   NSMutableDictionary *dic=[[NSMutableDictionaryalloc]initWithObjectsAndKeys:@"test2",@"username",@"820826",@"passWord",@"1EB2D9848C5545E6BAEAA10B01222800",@"clubUserid",@"西南大区",@"BigArea",@"",@"province",@"",@"city",nil];

   NSString *result2= [webServicegetResultWithURL:@"http://116.6.52.27:91/webservice/caskaforescService.asmx"xmlNS:nilmethod:@"GetClub"pars:dic];

    NSLog(@"%@",result2);

    [dic release];

    [result2 release];

    

    //方法二,取返回数据组

    NSArray *array=nil;

   NSMutableDictionary *dic2=[[NSMutableDictionaryalloc]initWithObjectsAndKeys:@"...",@"VerifyCode", @"",@"objParams",@"20120615170225282486",@"sAccountBookID", @"XYTY124",@"productModel", @"馨原奕绒",@"brandName", nil];

    array=[webServicegetArrayWithURL:@"http://resourceservice.41go.cn/systemupdate.asmx"xmlNS:nilmethod:@"GetProductPriceInfoExt"pars:dic2];

   NSLog(@"productmodel=%@;name=%@,key=%@",[arrayobjectAtIndex:2],[arrayobjectAtIndex:3],[arrayobjectAtIndex:10]);

   //判断数据中的空值(NSArray,NSMutableDictionary等)

    if ([array objectAtIndex:10]==[NSNullnull]) {

        NSLog(@"空值!");

    }

    [dic2 release];

   //方法三,取返回DataSet

    [webServiceinitDataSetWithURL:@"http://resourceservice.41go.cn/systemupdate.asmx"xmlNS:nilmethod:@"GetYarnList"pars:nil];

    NSMutableDictionary *wb=[webService.myDataset.TablesobjectForKey:@"YarnList"];//YarnList表名,如果没有命名则为Table

    NSInteger count=[[webService.myDataset.TablesobjectForKey:@"YarnList"]count];

    for (int ii=0; ii<count; ii++) {

        NSMutableDictionary *dictemp=[wb objectForKey:[NSStringstringWithFormat:@"%d",ii]];

       NSLog(@"col1=%@;col2=%@;col3=%@",[dictempobjectForKey:@"C_AccountBookID"],[dictempobjectForKey:@"C_Name"],[dictempobjectForKey:@"C_YarnID"]);

    }

 

    [webService release];

 

}

转载于:https://www.cnblogs.com/jgCho/p/4977263.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值