doc: add `json.decode([]Foo, sfoos)? example
parent
1fb127ba79
commit
914c1a527d
|
@ -1955,6 +1955,9 @@ fn caller() {
|
||||||
```v
|
```v
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
struct Foo {
|
||||||
|
x int
|
||||||
|
}
|
||||||
struct User {
|
struct User {
|
||||||
name string
|
name string
|
||||||
age int
|
age int
|
||||||
|
@ -1974,6 +1977,12 @@ user := json.decode(User, data) or {
|
||||||
println(user.name)
|
println(user.name)
|
||||||
println(user.last_name)
|
println(user.last_name)
|
||||||
println(user.age)
|
println(user.age)
|
||||||
|
|
||||||
|
// You can also decode JSON arrays:
|
||||||
|
sfoos := '[{"x":123},{"x":456}]'
|
||||||
|
foos := json.decode([]Foo, sfoos)?
|
||||||
|
println(foos[0].x)
|
||||||
|
println(foos[1].x)
|
||||||
```
|
```
|
||||||
|
|
||||||
Because of the ubiquitous nature of JSON, support for it is built directly into V.
|
Because of the ubiquitous nature of JSON, support for it is built directly into V.
|
||||||
|
|
Loading…
Reference in New Issue