Home parse IOS FBSDKGraphRequest result using Swift4 JSONDecoder
Reply: 1

parse IOS FBSDKGraphRequest result using Swift4 JSONDecoder

Ahmad Labeeb
1#
Ahmad Labeeb Published in 2017-12-07 07:57:04Z

the result of FBSDKGraphRequest is of type any and could be casting to NSDictionary, but how to convert it to Data object to be able to use this SWIFT4 feature

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

i'm try this but the result was nil as code comments

    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
}
Ahmad Labeeb
2#
Ahmad Labeeb Reply to 2017-12-07 09:22:37Z

it worked for me but i'm not sure if it is the optimal solution

let resDataFromDic = try? JSONSerialization.data(withJSONObject: resDict, options: JSONSerialization.WritingOptions.prettyPrinted)
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.299278 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO