Get json string from array iOS swift

 Solution:

func jsonStringFromArray(array:NSArray) -> String {

    var str = ""

    do {

        //Convert to Data

        let jsonData = try JSONSerialization.data(withJSONObject: array, options: JSONSerialization.WritingOptions.prettyPrinted)

        

        if let JSONString = String(data: jsonData, encoding: String.Encoding.utf8) {

            str = JSONString

        }

        

        var json = try JSONSerialization.jsonObject(with: jsonData, options: JSONSerialization.ReadingOptions.mutableContainers) as? [String: Any]

    } catch {

        print(error)

    }

    return str

}

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Saved Image in document directory and save path in coredata not able to fetch the image file iOS swift