Skip to content

Instantly share code, notes, and snippets.

@dral3x
Created October 1, 2017 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dral3x/55f1c25d639ac1f792412a78a7ee7b4d to your computer and use it in GitHub Desktop.
Save dral3x/55f1c25d639ac1f792412a78a7ee7b4d to your computer and use it in GitHub Desktop.
import UIKit
var output = [String: Any]()
for index in 0..<5 {
let mail = String(format: "%d@mail.com", index)
let name = String(format: "name_%d", index)
let id = NSNumber.init(value: index)
let item: [String: Any] = ["name": name, "id": id]
output[mail] = item
}
let jsonData = try? JSONSerialization.data(withJSONObject: output, options: .prettyPrinted)
let jsonString = String(data: jsonData!, encoding: String.Encoding.utf8)
print(jsonString!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment