Swift Encode Json

[Solved] Swift Encode Json | Swift - Code Explorer | yomemimo.com
Question : convert json to json string ios swift

Answered by : delightful-dingo-flr5uu11uolc

func jsonToString(json: AnyObject){ do { let data1 = try NSJSONSerialization.dataWithJSONObject(json, options: NSJSONWritingOptions.PrettyPrinted) // first of all convert json to the data let convertedString = String(data: data1, encoding: NSUTF8StringEncoding) // the data will be converted to the string print(convertedString) // <-- here is ur string } catch let myJSONError { print(myJSONError) } }

Source : https://stackoverflow.com/questions/36370541/how-to-convert-json-to-string-in-ios-swift | Last Update : Mon, 14 Mar 22

Question : swift encode json

Answered by : tayyab-mubeen

// for encoing your model or sturct must inherit codable protocol
var general = [str: products]
let encodedData = try? JSONEncoder().encode(general)

Source : | Last Update : Sun, 17 Apr 22

Answers related to swift encode json

Code Explorer Popular Question For Swift