我採取忘記密碼的服務中,我將通過一個電子郵件地址,它會返回JSON承認關於發送的電子郵件閱讀JSON。問題是我無法讀取json中的響應字符串,並且我的異常消息顯示data參數爲nil,但如果我在我的Web瀏覽器中查看該url,則服務看起來很好,如下所述。 我的代碼是:無法從服務
NSURL *url = [LokalmotionCommonTask getURLForgotPassword:emailFieldTxt.text];
NSData* data = [NSData dataWithContentsOfURL: url];
@try {
NSError* error;
NSDictionary* jsonDict = [NSJSONSerialization
JSONObjectWithData:data //1
options:0
error:&error];
NSLog(@"%@", [jsonDict objectForKey:@"response"]);
}
@catch (NSException *exception) {
NSLog(@"forgot password exception: %@: %@", [exception name], [exception reason]);
}
和服務響應我在Web瀏覽器中得到的是這樣的:
{"status":400,"response":"Your request to change password is already sent. Please check your email."}
例外:
forgot password exception: NSInvalidArgumentException: data parameter is nil
它在哪裏‘崩潰’到底是什麼? – Peres
它讀取的行是哪個jsonDict被實例化,然後拋出異常 – Firdous
那麼你有它,數據是零。 – Peres