HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了xcode – Alamorafire SwiftyJson FacebookSDK大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用FBSDK和 Xcode 7.2.1来检索用户配置文件信息,并使用 SwiftyJson来处理和操作json数据.更改值/删除一些后,我想使用JSON数据向我的api发送一个帖子请求.但是我很快就遇到了非常糟糕的类型问题.

这是我发布帖子请求的代码

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
 }

不幸的是我收到此错误

如果我尝试将JSON数据直接发送到API,我会收到此错误

任何帮助表示赞赏.我只是想知道,如何将JSON对象转换为String AnyObject?没有失败.或者使用Swift 2将Json对象作为post / put / patch请求数据发送.

解决方法

JSON是SwiftyJson中定义的自定义类型.尝试在您的情况下使用userProfile.DictionaryObject来获取底层的swift Dictionary.

通过此解包可选字典

if let userProfile = userProfile.DictionaryObject {
    Alamofire.request(.POST,error in
          print(userProfilE) //This prints nil
          print(responsE) //This prints api error for expecTing data
    }
}

大佬总结

以上是大佬教程为你收集整理的xcode – Alamorafire SwiftyJson FacebookSDK全部内容,希望文章能够帮你解决xcode – Alamorafire SwiftyJson FacebookSDK所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。