mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
json: fix decoding of structs with embeds (#22264)
This commit is contained in:
parent
7af312c542
commit
651a116159
2 changed files with 51 additions and 4 deletions
28
vlib/json/json_decode_embed_test.v
Normal file
28
vlib/json/json_decode_embed_test.v
Normal file
|
@ -0,0 +1,28 @@
|
|||
module main
|
||||
|
||||
import json
|
||||
|
||||
struct Json2 {
|
||||
inner []f64
|
||||
}
|
||||
|
||||
struct Json {
|
||||
Json2
|
||||
test f64
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
str := '{
|
||||
"inner": [1, 2, 3, 4, 5],
|
||||
"test": 1.0
|
||||
}'
|
||||
data := json.decode(Json, str) or {
|
||||
eprintln('Failed to decode json, error: ${err}')
|
||||
return
|
||||
}
|
||||
println(data)
|
||||
assert data.inner.len == 5
|
||||
assert data.inner[0] == 1.0
|
||||
assert data.inner[4] == 5.0
|
||||
assert data.test == 1.0
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue