Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

string to json swift

  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 by # #
 
PREVIOUS NEXT
Tagged: #string #json #swift
ADD COMMENT
Topic
Name
6+9 =