简体   繁体   English

如何解决错误:操作无法完成。 (可可错误3840。)json iOS?

[英]How to resolve error:the operation couldn’t be completed. (cocoa error 3840.) json iOS?

I wrote the GET method code to retrieve the details from server(json format).But I am getting the error (the operation could not be completed). 我写了GET方法代码来从服务器(json格式)中检索详细信息,但是我遇到了错误(操作无法完成)。 can anyone please provide me some information regarding this? 有人可以向我提供有关此信息吗? My code: 我的代码:

-(void)getResponseWithOutBodywithMethod:(NSString*)method
{
NSMutableURLRequest *request =
[NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:method];

//[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
// [request setTimeoutInterval:20.0];
 NSURLConnection *conn=[[NSURLConnection alloc]initWithRequest:request delegate:self];
if (conn)
{
    receivedData = [[NSMutableData alloc] init] ;
}
}
#pragma mark NSURLConnection delegate methods
- (void) connection:(NSURLConnection *)connection didReceiveResponse:  (NSURLResponse *)response{
/* This method is called when the server has determined that it has
 enough information to create the NSURLResponse. It can be called
 multiple times, for example in the case of a redirect, so each time
 we reset the data. */
[receivedData setLength:0];
}
- (void) connection:(NSURLConnection *)connection didReceiveData:  (    NSData *)data{
[receivedData appendData:data];
 }
 - (void) connection:(NSURLConnection *)connection didFailWithError:(  NSError *)error{
completion(nil, error);
NSLog(@"%@",[error localizedDescription]);

  }
    - (void) connectionDidFinishLoading:(NSURLConnection *)connection{

if (receivedData != nil) {
    NSError *jsonParsingError = nil;
    NSMutableDictionary *dict = [NSJSONSerialization JSONObjectWithData:receivedData
                                                         options:kNilOptions error:&jsonParsingError];

    NSString* str = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
    NSLog(@"error %@",jsonParsingError.localizedDescription);
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"ER" message:str delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alertView show];
    if (dict == nil && [dict count]==0) {

             UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:jsonParsingError.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alertView show];
         completion(nil, jsonParsingError);
    }
    else {

        completion(dict, nil);



    }
}
else {
    completion(nil, [NSError errorWithDomain:@"http" code:-1 userInfo:nil]); //todo proper error
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Failed to get data." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alertView show];
}
}

Well I would think your Json is the problem. 好吧,我认为您的Json是问题所在。

If your server is responding: 如果您的服务器响应:

Something=somethingelse 某物=其他

That's not the proper format. 那不是正确的格式。 You would need to Json encode it so it looks like: 您将需要对Json进行编码,使其看起来像:

[{"key":"value", "key":"value"}] [{“ key”:“ value”,“ key”:“ value”}]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS - Twitter连接问题:“操作无法完成。 (可可错误3840.)“ - iOS - Twitter Connectivity Issue: “The operation couldn’t be completed. (Cocoa error 3840.)” JSON解析错误:错误域= NSCocoaErrorDomain代码= 3840“该操作无法完成。(可可错误3840。) - JSON parse error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.) 错误域= NSCocoaErrorDomain代码= 3840“操作无法完成。(可可错误3840.) - Error Domain = NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.) 该操作无法完成。 (可可错误3840。)”(在字符16周围的对象中没有键值。) - The operation couldn’t be completed. (Cocoa error 3840.)" (No value for key in object around character 16.) 可可错误3840无法完成操作 - Cocoa error 3840 The operation couldn’t be completed 该操作无法完成。 (可可错误-1。) - PHPhotoLibrary - The operation couldn’t be completed. (Cocoa error -1.) - PHPhotoLibrary 该操作无法完成。 (可可错误133021.)+迅捷2 - The operation couldn’t be completed. (Cocoa error 133021.) + swift 2 该操作无法完成。 (可可错误1560.) - The operation couldn’t be completed. (Cocoa error 1560.) 错误:错误域= NSCocoaErrorDomain代码= 3840“该操作无法完成。 - Error:Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. Phonegap,可可错误257-操作无法完成。 不允许操作 - Phonegap, Cocoa error 257 - The operation couldn’t be completed. Operation not permitted
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM