我在Objective-C和和建設網頁的標誌特定網站新。當用戶提供信息下面的JSON從服務器返回回:JSON解析與iOS 6和Xcode的4.5.2
{
"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
如果你確實找到了解決方案,請發佈它。謝謝。 – androniennn