From 356c1005b3b4b220fd83700450a7faf1c55d752e Mon Sep 17 00:00:00 2001 From: Zach Date: Mon, 6 Mar 2023 17:19:37 -0700 Subject: [PATCH] Update JSON.swift --- Sources/Cache/JSON.swift | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Sources/Cache/JSON.swift b/Sources/Cache/JSON.swift index ef92057..36a499a 100644 --- a/Sources/Cache/JSON.swift +++ b/Sources/Cache/JSON.swift @@ -5,15 +5,19 @@ import c To create a `JSON` object, pass a `Data` object that contains JSON data to the `init(data:)` method. You can then use the `get(_:)` or `resolve(_:)` method to extract individual values from the JSON data. - let jsonData = "{\"name\": \"John Doe\", \"age\": 42}".data(using: .utf8)! - let json = JSON(data: jsonData) +```swift +let jsonData = "{\"name\": \"John Doe\", \"age\": 42}".data(using: .utf8)! +let json = JSON(data: jsonData) - let name: String = try json.resolve(.name) - let age: Int = try json.resolve(.age) +let name: String = try json.resolve(.name) +let age: Int = try json.resolve(.age) +``` You can also use the `set(value:forKey:)` method to update the values in the JSON object, and the `get(_:)` or `resolve(_:)` method to retrieve the values from the object. - json.set(value: "Jane Doe", forKey: .name) - let newName: String = try json.resolve(.name) +```swift +json.set(value: "Jane Doe", forKey: .name) +let newName: String = try json.resolve(.name) +``` */ public typealias JSON = c.JSON