Update JSON.swift

This commit is contained in:
Zach 2023-03-06 17:19:37 -07:00 committed by GitHub
parent cab86f47a1
commit 356c1005b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 6 deletions

View File

@ -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. 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)! ```swift
let json = JSON<MockJSONKey>(data: jsonData) let jsonData = "{\"name\": \"John Doe\", \"age\": 42}".data(using: .utf8)!
let json = JSON<MockJSONKey>(data: jsonData)
let name: String = try json.resolve(.name) let name: String = try json.resolve(.name)
let age: Int = try json.resolve(.age) 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. 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) ```swift
let newName: String = try json.resolve(.name) json.set(value: "Jane Doe", forKey: .name)
let newName: String = try json.resolve(.name)
```
*/ */
public typealias JSON = c.JSON public typealias JSON = c.JSON