错误域= NSCocoaErrorDomain代码= 3840“无法完成操作

错误域= NSCocoaErrorDomain代码= 3840“无法完成操作

问题描述:

I have used link code for send and get json data.

I modified the code for sync data with the web server using following code.

- (IBAction)syncTickets:(id)sender {

 [self postTest];
 [self getTest];

}

I have overide getTest function to save data into the phone database. I got an 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=0x987b960 {NSDebugDescription=JSON text did not start
with array or object and option to allow fragments not set.
}

It only happens when i am syncing for the first time afterwards it works fine. Can you suggest me a solution .

我使用了链接代码。 p>

我修改了同步数据的代码 使用以下代码的Web服务器。 p>

   - (IBAction)syncTickets:(id)sender {
 
 [self postTest]; 
 [self getTest]; 
  
} 
  code>  pre> 
 
 

我有覆盖getTest函数以将数据保存到手机数据库中。 我收到错误 p>

 错误Domain = NSCocoaErrorDomain Code = 3840“操作无法完成。
(Cocoa error 3840.)”(JSON文本未启动 使用数组或对象和选项来允许未设置
fragments。)UserInfo = 0x987b960 {NSDebugDescription = JSON文本未启动
与数组或对象和选项以允许未设置片段。
} 
  code>  pre  > 
 
 

只有在我第一次同步后才能正常工作。 你能给我一个解决方案。 p> div>

I have already given answer here,

The same answer as above

It may possible that, the response from your server doesn't contain valid JSON.

Technically, The JSON object must be start with either an "array" or an "object (dictionary)".

So, Whatever your server is returning isn't.

And, you can force the JSON to be consumed regardless by using the NSJSONReadingAllowFragments option.

by using ,

AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];