简单地说就是我做的一个登录验证从网站返回的数据,我现在要把数据解析出来但是我不会呀。.h文件为#import
#import "JSONKit.h"
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *username;
@property (weak, nonatomic) IBOutlet UITextField *pwd;
- (IBAction)signin:(id)sender;
@end
.m文件为
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(BOOL)textFieldShouldReturn:(UITextField*)textField{
[textField resignFirstResponder];
return YES;
}
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.
}
(void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}-
(IBAction)signin:(id)sender {
NSString*username=self.username.text;
NSString*pwd=self.pwd.text;
NSString *str =[NSString stringWithFormat:@"ActionCode=0x2001¶meter=pwd###%@#####userNo###%@&LoginID=&LoginIp=",pwd,username];//设置参数NSString *encodedValue = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString*str2=[NSString stringWithFormat:@"http://14.17.84.128:8088/wcf/ActionService.svc/action/web/get/do?%@",encodedValue];
NSURL*url=[NSURL URLWithString:str2];
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
//NSURLRequest初始化方法第一个参数:请求访问路径,第二个参数:缓存协议,第三个参数:网络请求超时时间(秒)
//第三步,连接服务器
NSData *received = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *str3 = [[NSString alloc]initWithData:received encoding:NSUTF8StringEncoding];
// NSLog(@"%@",str2);
NSLog(@"%@",str3);
}
@end接受到的数据为2015-08-10 21:36:37.038 百汇百通[626:6884] {"ErrorCode":0,"Exception":null,"IsCompleted":true,"Result":"{\"CompanyCode\":\"100000\",\"CompanyID\":\"1\",\"CompanyName\":\"百汇百通位置服务平台\",\"DataRights\":\"ALL\",\"GprsPort\":\"\",\"GpsDeviceNo\":\"\",\"GpsDeviceType\":\"\",\"LicensePlate\":\"\",\"Privileges\":\"ALL\",\"Result\":\"0\",\"RoleID\":\"1\",\"RoleName\":\"系统管理员\",\"SimcardNo\":\"\",\"UserName\":\"超级管理员\",\"UserType\":\"1\",\"VehicleID\":\"\"}"}大神告诉我如何解析并提取键值呀。