mirror of
https://github.com/vlang/v.git
synced 2025-09-08 06:41:58 -04:00
x.json2.decoder2: support nesteded maps (#23027)
This commit is contained in:
parent
e421cb2bc2
commit
d8021bd459
@ -322,7 +322,7 @@ fn (mut checker Decoder) check_json_format(val string) ! {
|
||||
}
|
||||
}
|
||||
}
|
||||
if checker.checker_idx < checker_end - 1 {
|
||||
if checker.checker_idx < checker_end - 2 {
|
||||
checker.checker_idx++
|
||||
}
|
||||
}
|
||||
@ -748,9 +748,12 @@ fn (mut decoder Decoder) decode_map[K, V](mut val map[K]V) ! {
|
||||
|
||||
mut map_value := V{}
|
||||
|
||||
decoder.decode_value(mut map_value)!
|
||||
|
||||
val[key] = map_value
|
||||
$if V is $map {
|
||||
val[key] = map_value.move()
|
||||
} $else {
|
||||
val[key] = map_value
|
||||
}
|
||||
decoder.decode_value(mut val[key])!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,14 +39,16 @@ fn test_array_of_strings() {
|
||||
assert json.decode[map[string]string]('{"val": "2"}')! == {
|
||||
'val': '2'
|
||||
}
|
||||
// assert json.decode[map[string]int]('{"val": 2}')! == {"val": 2}
|
||||
assert json.decode[map[string]int]('{"val": 2}')! == {
|
||||
'val': 2
|
||||
}
|
||||
|
||||
// // nested map
|
||||
// assert json.decode[map[string]map[string]string]('{"val": {"val2": "2"}}')! == {
|
||||
// 'val': {
|
||||
// 'val2': '2'
|
||||
// }
|
||||
// }
|
||||
// nested map
|
||||
assert json.decode[map[string]map[string]string]('{"val": {"val2": "2"}}')! == {
|
||||
'val': {
|
||||
'val2': '2'
|
||||
}
|
||||
}
|
||||
|
||||
// nested struct
|
||||
assert json.decode[Stru]('{"val": 1, "val2": "lala", "val3": {"a": 2, "brazilian_steak": "leleu"}}')! == Stru{
|
||||
|
Loading…
x
Reference in New Issue
Block a user