我已经使用link代码发送和获取json数据。
我使用以下代码修改了用于与Web服务器同步数据的代码。
- (IBAction)syncTickets:(id)sender {
[self postTest];
[self getTest];
}
我具有覆盖getTest函数,可将数据保存到电话数据库中。我收到一个错误:
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.
}
仅在此后第一次进行同步时,它才能正常工作。
我已经给出了答案here,
与上述相同的答案
[您的服务器的响应可能不包含有效的JSON。
从技术上讲,JSON对象必须以“数组”或“对象(字典)”开头。
因此,无论您的服务器返回的是什么。
而且,您可以通过使用NSJSONReadingAllowFragments选项强制使用JSON。
使用,
AFJSONResponseSerializer *responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];