ris*_*992 2 json apple-push-notifications ios sendasynchronousrequest
我在服务器上注册设备数据,以获得推送通知.这是代码,
[NSURLConnection sendAsynchronousRequest: request
queue: _postQueue
completionHandler: ^(NSURLResponse *response, NSData *responseData, NSError *connectionError) {
if (connectionError) {
//
} else {
NSError *error = nil;
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData: responseData options: NSJSONReadingMutableContainers error: &error];
}
}];
Run Code Online (Sandbox Code Playgroud)
我得到的错误是
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=0x17057f60 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙解决问题吗?
错误消息告诉您确切的错误:服务器的响应不包含有效的JSON.从技术上讲,JSON必须以数组或对象(字典)开头.无论您的服务器返回什么,都不是.无论使用哪个NSJSONReadingAllowFragments选项,都可以强制使用JSON .
如果在使用该选项后仍然出现错误,那么您的服务器可能会返回格式错误的JSON(或根本没有JSON).为什么不查看服务器上的日志以确切了解您要发回的内容?
| 归档时间: |
|
| 查看次数: |
23436 次 |
| 最近记录: |