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:
parent
71bff213ef
commit
9242d4b79b
@ -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"]}
|
||||
|
Loading…
Reference in New Issue
Block a user