Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

convert data to json swift

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

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)
            }
        }
Comment

convert json to json string ios swift

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)
        }

    }
Comment

convert json to json string ios swift

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)
        }

    }
Comment

PREVIOUS NEXT
Code Example
Swift :: uiimage to data swift 
Swift :: swift navigation bar title color 
Swift :: We use the for loop to iterate over the elements of a dictionary. 
Swift :: try? as? in swiftui 
Swift :: Delete Realm database swift 
Swift :: change font swiftui 
Swift :: swift arrays 
Swift :: change individual element alignment swiftui 
Swift :: set in swift 
Swift :: swift 5 make image fit uiimageview 
Swift :: navigationbarhidden not working swiftui 
Swift :: remove key by index dictionary swift 
Swift :: how can i find range of a string in another string swift 
Swift :: Swift Nested function 
Swift :: deselect all cell in collectionview 
Swift :: replace back button image swift 
Swift :: swift guard statement 
Swift :: ios get notification payload 
Swift :: swiftui selection list 
Swift :: Swift nal Within The Same Module 
Swift :: Swift Change Value of Dictionary 
Swift :: Swift enum With Switch Statement 
Swift :: Swift break statement with nested loops 
Swift :: swiftui calendar 
Swift :: flow ios swift kotlin 
Swift :: Swift Comparison Operators 
Swift :: Swift mutating Methods 
Swift :: swift error handling 
Swift :: while loop swift 
Ruby :: ruby array group by attribute 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =