Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/JSON/Swift/json.swift
Normal file
19
Task/JSON/Swift/json.swift
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import Foundation
|
||||
|
||||
let jsonString = "{ \"foo\": 1, \"bar\": [10, \"apples\"] }"
|
||||
if let jsonData = jsonString.data(using: .utf8) {
|
||||
if let jsonObject: Any = try? JSONSerialization.jsonObject(with: jsonData, options: .allowFragments) {
|
||||
print("Dictionary: \(jsonObject)")
|
||||
}
|
||||
}
|
||||
|
||||
let obj = [
|
||||
"foo": [1, "Orange"],
|
||||
"bar": 1
|
||||
] as [String : Any]
|
||||
|
||||
if let objData = try? JSONSerialization.data(withJSONObject: obj, options: .prettyPrinted) {
|
||||
if let jsonString2 = String(data: objData, encoding: .utf8) {
|
||||
print("JSON: \(jsonString2)")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue