我是 Objective-c 的新手,并且正在为特定网站构建登录页面。当用户提供信息时,服务器会返回以下 JSON:
{
"object":{},
"resultCode":0,
"resultMessage":"You successfully signed in "
}
这就是我根据我找到的教程尝试做的事情:
-(IBAction)login{
// Download JSON
NSData *data = [NSData dataWithContentsOfURL: [NSURL URLWithString:[NSString stringWithFormat:@"https://www.example.com/login?username=%@&password=%@", nationalID.text,passowrd.text]]];
NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSArray *response = [json objectForKey:@"resultMessage"];
NSLog(@"response %@",response);
}
我想注销“resultMessage”,但不知何故它抛出了一个异常:
2012-12-13 06:46:50.607 myProject[7178:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'
*** First throw call stack:
(0x1c8d012 0x10cae7e 0x1c8cdeb 0xbff817 0x2f1a 0x10de705 0x15920 0x158b8 0xd6671 0xd6bcf 0xd5d38 0x4533f 0x45552 0x233aa 0x14cf8 0x1be8df9 0x1be8ad0 0x1c02bf5 0x1c02962 0x1c33bb6 0x1c32f44 0x1c32e1b 0x1be77e3 0x1be7668 0x1265c 0x279d 0x26c5)
libc++abi.dylib: terminate called throwing an exception