Gitly
English
Русский
Español
日本語
中文
Português
Pricing
Log in
Register
vxx
/
vlib
/
v
/
gen
/
c
/
testdata
/
json_option_decode_cast.vv
23
lines
·
19
sloc
·
248 bytes
·
1779638616
Raw
1
module main
2
3
import json
4
5
struct Bar {
6
name string
7
}
8
9
struct Foo {
10
a ?int
11
b ?[]Bar
12
}
13
14
fn main() {
15
src := '{"a": 1, "b": [{"name": "x"}]}'
16
f := json.decode(Foo, src) or { return }
17
if v := f.a {
18
println(v)
19
}
20
if v := f.b {
21
println(v)
22
}
23
}
24