【发布时间】:2015-02-12 17:16:58
【问题描述】:
在我的整个项目中,我可以完美地检查 Alamofire 的响应和数据
if fooData != nil {
//do stuff
}
在这种情况下,Swift 似乎在检查实际传入类型时遇到了问题
如果我打印它会得到什么
<null>
这应该是什么?一个空数组?强制转换为 NSDictionary 或 NSArray 均失败。
Rest 响应与在整个项目中始终相同,我可能会收到一个空值,并且它会在其他任何地方被捕获。
€dit 更多代码: 我的要求:
Alamofire.request(.GET, "\(CurrentConfiguration.serverURL)/api/users/\(CurrentConfiguration.currentUser.id)/friends/\(targetUser)",encoding:.JSON)
.validate()
.responseJSON {(request, response, friendData, error) in
if friendData != nil {
println(friendData!)
//this is where the app obviously crashes as there is nothing inside of "friendData"
let resp = friendData as NSDictionary
//load friendData into the UI
}
}
print 语句给了我上面提到的 null 表示,但显然不能识别为 nil
来自节点后端的响应是
index.sendJsonResponse(res, 200, null);
【问题讨论】:
-
你能发布你的实际代码吗?
-
我同意,如果您没有代码,这将很难提供帮助。
-
用代码编辑了第一篇文章