gpt4 book ai didi

ios - 使用 Swift4 JSONDecoder 解析 IOS FBSDKGraphRequest 结果

转载 作者:行者123 更新时间:2023-11-30 11:57:04 25 4
gpt4 key购买 nike

FBSDKGraphRequest的结果属于 any 类型,可以转换为 NSDictionary ,但是如何将其转换为Data对象能够使用这个 SWIFT4特点

let jsonDecoder = JSONDecoder.init()
let fbModel = try? jsonDecoder.decode(FBModel.self, from: dataFromResult)

我正在尝试这个,但结果是零作为代码注释

    FBSDKGraphRequest.init(graphPath: "me", parameters: ["fields":"email,name,id"]).start{ (connection, results, error) -> Void in
let dataFromResult = NSKeyedArchiver.archivedData(withRootObject: results)
let stringFromData = String.init(data: dataFromResult, encoding: String.Encoding.utf8)//return nil
let jsonDecoder = JSONDecoder.init()
let fbModel = try? jsonDecoder.decode(FBModel.self, from: dataFromResult)//fbModel nil
}

最佳答案

它对我有用,但我不确定这是否是最佳解决方案

let resDataFromDic = try? JSONSerialization.data(withJSONObject: resDict, options: JSONSerialization.WritingOptions.prettyPrinted)

关于ios - 使用 Swift4 JSONDecoder 解析 IOS FBSDKGraphRequest 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47690197/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com