2012-12-13 65 views
0

我在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 
+0

如果你確實找到了解決方案,請發佈它。謝謝。 – androniennn

回答

0

,如果你能看到問題描述:

「NSInvalidArgumentException」的,理由是:「數據參數是零」

指從網站的網址您迴應的迴應是零或NULL
這是不相關的JSON解析器問題。

+0

感謝您的嘗試 – Timmy

2

看起來像-dataWithContentsOfURL:消息失敗並返回nil,這正是錯誤消息所說的內容。您需要確認您的-stringWithFormat:消息正在爲您提供正確的URL格式,並檢查服務器是否正在返回您所期望的。

+0

謝謝,這解決了我的問題。 – Timmy

0

看起來你有一個簡單的拼寫錯誤,您正在使用:

nationalID.text,passowrd.text 

你大概意思不是拼錯的「密碼」。