1
以下(無效的周圍字符0的值)是代碼錯誤域= NSCocoaErrorDomain代碼= 3840「該操作不能完成。(可可錯誤3840)」
NSDictionary *post = [NSDictionary dictionaryWithObjectsAndKeys:
@"signup",@"methodName",_tfName.text,@"name",_tfNickName.text,@"nickname",
_dateOfBirth.text, @"birth_date",
@"1",@"gender",
_tfEmail.text,@"email",
_tfPassword.text,@"password",
_tfContact.text, @"mobile",
_tfCountry.text,@"country",
@"Normal",@"social_provider",
@"",@"social_accesstoken",@"3",@"sponsor_choice" ,_tfPinCode.text,@"pincode",@"",
@"fromLogin",nil];
這是過賬的實際過程數據
NSData *postdata = [NSJSONSerialization dataWithJSONObject:post options:NSJSONWritingPrettyPrinted error:nil];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://[email protected]"]]];
[request setHTTPMethod:@"POST"];
[request setValue:@"multipart/form-data" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postdata];
NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
if(conn)
{
NSLog(@"Connection Successful");
}
else
{
NSLog(@"Connection could not be made");
}
}
代表的URLConnection
- (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse *)response
{
NSLog(@"Did Receive Response %@", response);
responseData = [[NSMutableData alloc]init];
}
- (void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data
{
//NSLog(@"Did Receive Data %@", data);
[responseData appendData:data];
}
這裏我得到的值的響應數據
- (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error
{
NSLog(@"Did Fail");
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"Did Finish");
NSError *error = nil;
NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&error];
NSLog(@"Array: %@", jsonArray);
// Do something with responseData
}
其實我把jsonarray的價值定爲零。即使我從服務器獲得響應數據的價值。
您可以登錄在'connectionDidFinishLoading:':'的NSString *海峽= [[NSString的頁頭] initWithData:responseData編碼:NSUTF8StringEncoding] '? – Larme
它顯示HTML內容 –
而內容似乎有效(我的意思是,返回的數據是正確的,而不是格式化的方式,但他們有意義)?那麼它不是JSON。如果您使用POSTMan(或類似的)進行測試,您的服務是否響應JSON? – Larme