Skip to content

Instantly share code, notes, and snippets.

@chenr2
Last active August 29, 2015 14:25
Show Gist options
  • Save chenr2/665425f0b30c2abfa011 to your computer and use it in GitHub Desktop.
Save chenr2/665425f0b30c2abfa011 to your computer and use it in GitHub Desktop.
Swift: JSON stringify

How to stringify JSON

This assumes you have SwiftyJSON.

Start with a Dictionary

let paramsDictionary = [
    "title": "foo",
    "description": "bar"
]

First convert a Dictionary to JSON

let paramsJSON = JSON(paramsDictionary)

Then convert the JSON to a string.

let paramsString = paramsJSON.rawString(encoding: NSUTF8StringEncoding, options: nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment