我使用FBSDK和Xcode 7.2.1来检索用户配置文件信息并使用SwiftyJson处理和操作json数据。在更改值/删除一些我想要使用JSON数据发送到我的API的发布请求。但是我很快就遇到了非常糟糕的类型问题。Alamorafire + SwiftyJson + FacebookSDK
这是我的代码,以使POST请求:
let headers = [
"Content-Type": "application/json"
]
let userProfile = userProfile as? [String : AnyObject]
Alamofire.request(.POST, "http://localhost:8888/api/profile", parameters: userProfile, headers: headers, encoding:ParameterEncoding.URL) .response { request, response, data, error in
print(userProfile) //This prints nil
print(response) //This prints api error for expecting data
}
不幸的是我收到此错误:
Cast from 'JSON' to unrelated type '[String : AnyObject]' always fails
如果我尝试将JSON数据直接发送到API我收到此错误:
Cannot convert value of type 'JSON' to expected argument type '[String : AnyObject]?'
任何帮助表示赞赏。我只想知道,如何将JSON对象转换为String AnyObject?没有失败。或发送JSON对象作为后/ PUT /补丁请求数据与夫特2.
尝试从.URL改变编码以.json –
这不是问题。没有工作.. – artuc
没问题,你可以分享userProfile的数据? –