1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

json2: minor cleanup in README.md (#16096)

This commit is contained in:
yuyi 2022-10-18 23:00:14 +08:00 committed by GitHub
parent 71bff213ef
commit 9242d4b79b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,10 +10,10 @@ import net.http
fn main() {
// Decoding
resp := http.get('https://example.com')?
resp := http.get('https://example.com')!
// raw decode
raw_person := json2.raw_decode(resp.body)?
raw_person := json2.raw_decode(resp.body)!
// Casting `Any` type / Navigating
person := raw_person.as_map()
@ -90,8 +90,8 @@ fn (p Person) to_json() string {
}
fn main() {
resp := os.read_file('./person.json')?
person := json2.decode<Person>(resp)?
resp := os.read_file('./person.json')!
person := json2.decode<Person>(resp)!
println(person) // Person{name: 'Bob', age: 28, pets: ['Floof']}
person_json := json2.encode<Person>(person)
println(person_json) // {"name": "Bob", "age": 28, "pets": ["Floof"]}