Created
March 10, 2017 13:35
-
-
Save 4np/1d96c5d06be69cfc59749f753fb46458 to your computer and use it in GitHub Desktop.
Creating JSON in Swift (Playground)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
//[{ | |
// "508d49e5d7200200b96d45a3ce6103c4":[{ // filter widget id | |
// "table":"incident", | |
// "filter":"categoryINsoftware" | |
// }], | |
// "id":”508d49e5d7200200b96d45a3ce6103c4” // filter widget id | |
//}] | |
let filterParameters: [String: String] = [ | |
"table": "incident", | |
"filter": "categoryINsoftware" | |
] | |
let filter: [String: Any] = [ | |
"508d49e5d7200200b96d45a3ce6103c4": [filterParameters], | |
"id": "508d49e5d7200200b96d45a3ce6103c4" | |
] | |
let json: [Any] = [filter] | |
let valid = JSONSerialization.isValidJSONObject(json) // true | |
do { | |
let jsonData = try JSONSerialization.data(withJSONObject: json, options: []) | |
let jsonString = String(data: jsonData, encoding: .utf8)! | |
print(jsonString) | |
} catch let error { | |
print("error") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment