加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

webservice返回json数据

发布时间:2020-12-17 00:24:03 所属栏目:安全 来源:网络整理
导读:? webservice返回json数据 - (IBAction)webServicexRequestPost:(UIButton *)sender{ //构建webservice请求字符串 NSLog(@"开始构建字符串"); NSString*soapMessage=[NSString stringWithFormat:pre class="brush:objc; toolbar: true; auto-links: false;"
?
webservice返回json数据 - (IBAction)webServicexRequestPost:(UIButton *)sender{ //构建webservice请求字符串 NSLog(@"开始构建字符串"); NSString*soapMessage=[NSString stringWithFormat:<pre class="brush:objc; toolbar: true; auto-links: false;"> 请把代码粘贴在这里<pre class="brush:objc; toolbar: true; auto-links: false;"> 请把代码粘贴在这里 <pre class="brush:objc; toolbar: true; auto-links: false;"> 请把代码粘贴在这里 </pre> </pre> </pre> @"{"Username":"%@","Password":"%@"}",self.UserName.text,self.PassWord.text]; NSString*msgLength=[NSString stringWithFormat:@"%d",[soapMessage length]]; NSLog(@"调用webservice的字符串是%@",soapMessage); //设置请求地址 NSURL*url=[NSURL URLWithString:@"http://XXXXXXXX/Login"]; NSMutableURLRequest*urlRequest=[NSMutableURLRequest requestWithURL:url]; //请求头文件 ? ? [urlRequest addValue: @"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; ?? [urlRequest addValue: @"Login" forHTTPHeaderField:@"SOAPAction"]; ?? [urlRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; //设置请求方式 ? ? [urlRequest setHTTPMethod:@"POST"]; ? ? [urlRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; ? ? NSURLResponse *response; ? ? NSError*error=nil; //接受返回数据 NSData*responseData=[NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error]; NSMutableString*result=[[NSMutableString alloc]initWithData:responseData encoding:NSUTF8StringEncoding ]; NSLog(@"return string is============>>%@",result); //解析返回的数据 SBJsonParser*parser=[[SBJsonParser alloc]init ]; ? ? NSError*JSONError=nil; ? ? NSMutableDictionary*jsonDil=[parser objectWithString:result error:&JSONError ]; ? ? NSLog(@"%@",[jsonDil objectForKey:@"d"]); } 这样返回的就是一个json的数据结构

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读