Answers for "swift string to dictionary"

2

swift convert data to dictionary

do{  
let json = try JSONSerialization.jsonObject(with: data!, options: []) as? [String : Any]
}catch{ print("erroMsg") }
Posted by: Guest on January-13-2022
0

swift string to dictionary

func convertStringToDictionary(text: String) -> [String:AnyObject]? {
    if let data = text.data(using: .utf8) {
        do {
            let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String:AnyObject]
            return json
        } catch {
            print("Something went wrong")
        }
    }
    return nil
}
Posted by: Guest on April-07-2022

Code answers related to "swift string to dictionary"

Code answers related to "Swift"

Browse Popular Code Answers by Language