Convert Json To Json String Ios Swift

[Solved] Convert Json To Json String Ios Swift | Swift - Code Explorer | yomemimo.com
Question : convert data to json swift

Answered by : ahsan-lwa8tagab3go

do{
let json = try JSONSerialization.jsonObject(with: data!, options: []) as? [String : Any]
}catch{ print("erroMsg") }

Source : https://stackoverflow.com/questions/39427500/swift-3-0-data-to-json-string-any | Last Update : Thu, 20 Jan 22

Question : string to json swift

Answered by : dero-nara

 let jsonText = "{\"first_name\":\"Sergey\"}" var dictonary:NSDictionary? if let data = jsonText.data(using: String.Encoding.utf8) { do { dictonary = try JSONSerialization.jsonObject(with: data, options: []) as? [String:AnyObject] if let myDictionary = dictonary { print(" First name is: \(myDictionary["first_name"]!)") } } catch let error as NSError { print(error) } }

Source : https://www.youtube.com/watch?v=tQuFrRuEgNo | Last Update : Wed, 20 Apr 22

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

Answers related to convert json to json string ios swift

Code Explorer Popular Question For Swift