简体   繁体   English

错误域= NSCocoaErrorDomain代码= 3840“操作无法完成。(可可错误3840.)

[英]Error Domain = NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)

I am requesting dynamic json string from web url. 我从web url请求动态json字符串。

-(void)getDataFromServer{

 NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.domain.com/json/"]];

[request setHTTPMethod:@"GET"];
[request addValue:@"getValues" forHTTPHeaderField:@"METHOD"]; 

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}



-(void)requestReturnedData:(NSData *)data{ //activated when data is returned

 NSDictionary *dictionary = [NSDictionary dictionaryWithJSONData:data];

}

I got below error. 我得到了以下错误。

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa  error 3840.)(JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x977a900 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

I have tested with json text file 我用json文本文件测试过

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.domain.com/jsonfile.json"]];

It works perfectly. 它完美地运作。 How can i overcome this issue. 我怎样才能克服这个问题。

Edit--- 编辑 - -

I have found that , if number of rows in json exeeding 200 this error happens. 我发现,如果json中的行数超过200,则会发生此错误。 Otherwise it runs perfectly. 否则它运行得很好。 is there a issue with data size. 是否存在数据大小问题。

I got the same problem and found the solution for my code. 我遇到了同样的问题,并为我的代码找到了解决方案。 When connection returns large data method "didReceiveData" calls many time with the chunk of data recieved. 当连接返回大数据方法时,“didReceiveData”会在接收到大量数据的情况下多次调用。 We have to append the data of this method to NSData reference declared in .h file of the parser class. 我们必须将此方法的数据附加到解析器类的.h文件中声明的NSData引用。 And should call the method "dictionaryWithJSONData" in the delegate method of NSURLConnection "connectionDidFinishLoading". 并且应该在NSURLConnection“connectionDidFinishLoading”的委托方法中调用方法“dictionaryWithJSONData”。

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{

[self.dataJSON appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    NSDictionary *dictionary = [NSDictionary dictionaryWithJSONData:dataJSON];
}

Here dataJSON is declared at .h file and allocated in the init method. 这里dataJSON在.h文件中声明并在init方法中分配。

暂无
暂无

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

相关问题 JSON解析错误:错误域= NSCocoaErrorDomain代码= 3840“该操作无法完成。(可可错误3840。) - JSON parse error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.) 错误:错误域= NSCocoaErrorDomain代码= 3840“该操作无法完成。 - Error:Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. 如何解决错误:操作无法完成。 (可可错误3840。)json iOS? - How to resolve error:the operation couldn’t be completed. (cocoa error 3840.) json iOS? iOS - Twitter连接问题:“操作无法完成。 (可可错误3840.)“ - iOS - Twitter Connectivity Issue: “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.) 错误域=NSCocoaErrorDomain 代码=3840“无法在 iOS 中使用 AFNetworking 完成操作 - Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed in iOS using AFNetworking Error Domain = NSCocoaErrorDomain Code = 3840“无法使用AFNetworking完成操作 - Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed using AFNetworking 可可错误3840无法完成操作 - Cocoa error 3840 The operation couldn’t be completed Domain = NSCocoaErrorDomain代码= 3840“操作无法完成 - Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed checkResourceIsReachableAndReturnError总是返回Domain = NSCocoaErrorDomain Code = 4“操作无法完成。 (可可错误4。)” - checkResourceIsReachableAndReturnError always return Domain=NSCocoaErrorDomain Code=4 “The operation couldn’t be completed. (Cocoa error 4.)”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM