微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

webservice返回json数据

 
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的数据结构

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐