Skip to content

Instantly share code, notes, and snippets.

@DuncanMC
Created April 14, 2015 12:57
Show Gist options
  • Save DuncanMC/fef1845a23dba5e217fb to your computer and use it in GitHub Desktop.
Save DuncanMC/fef1845a23dba5e217fb to your computer and use it in GitHub Desktop.
A short Swift snippet demonstrating how to convert a dictionary to JSON
import UIKit
import AVFoundation
let dictionary = ["aKey": "aValue", "anotherKey": "anotherValue"]
let theJSONData = NSJSONSerialization.dataWithJSONObject(
dictionary ,
options: NSJSONWritingOptions.PrettyPrinted,
error: nil)
let theJSONText = NSString(data: theJSONData!,
encoding: NSASCIIStringEncoding)
println("JSON string = \(theJSONText!)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment