mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
x.json2: fix compilation with -autofree
This commit is contained in:
parent
5deb56fc79
commit
1913de0187
@ -142,6 +142,7 @@ fn (mut p Parser) decode_value() ?Any {
|
||||
return Any(null)
|
||||
}
|
||||
|
||||
[manualfree]
|
||||
fn (mut p Parser) decode_array() ?Any {
|
||||
mut items := []Any{}
|
||||
p.next_with_err() ?
|
||||
|
@ -19,6 +19,7 @@ fn write_value(v Any, i int, len int, mut wr strings.Builder) {
|
||||
}
|
||||
|
||||
// str returns the string representation of the `map[string]Any`.
|
||||
[manualfree]
|
||||
pub fn (flds map[string]Any) str() string {
|
||||
mut wr := strings.new_builder(200)
|
||||
wr.write_b(`{`)
|
||||
@ -37,6 +38,7 @@ pub fn (flds map[string]Any) str() string {
|
||||
}
|
||||
|
||||
// str returns the string representation of the `[]Any`.
|
||||
[manualfree]
|
||||
pub fn (flds []Any) str() string {
|
||||
mut wr := strings.new_builder(200)
|
||||
wr.write_b(`[`)
|
||||
|
@ -16,10 +16,10 @@ pub mut:
|
||||
|
||||
fn (e Employee) to_json() string {
|
||||
mut mp := map[string]json2.Any{}
|
||||
mp['name'] = e.name
|
||||
mp['age'] = e.age
|
||||
mp['salary'] = e.salary
|
||||
mp['title'] = int(e.title)
|
||||
mp['name'] = json2.Any(e.name)
|
||||
mp['age'] = json2.Any(e.age)
|
||||
mp['salary'] = json2.Any(e.salary)
|
||||
mp['title'] = json2.Any(int(e.title))
|
||||
/*
|
||||
$for field in Employee.fields {
|
||||
d := e.$(field.name)
|
||||
@ -36,10 +36,10 @@ fn (e Employee) to_json() string {
|
||||
|
||||
fn (mut e Employee) from_json(any json2.Any) {
|
||||
mp := any.as_map()
|
||||
e.name = mp['name'] or { 0 }.str()
|
||||
e.age = mp['age'] or { 0 }.int()
|
||||
e.salary = mp['salary'] or { 0 }.f32()
|
||||
e.title = JobTitle(mp['title'] or { 0 }.int())
|
||||
e.name = mp['name'] or { json2.Any('') }.str()
|
||||
e.age = mp['age'] or { json2.Any(0) }.int()
|
||||
e.salary = mp['salary'] or { json2.Any(0) }.f32()
|
||||
e.title = JobTitle(mp['title'] or { json2.Any(0) }.int())
|
||||
}
|
||||
|
||||
fn test_simple() {
|
||||
@ -157,10 +157,10 @@ fn (u User) to_json() string {
|
||||
'age': json2.Any(u.age)
|
||||
}
|
||||
mp['nums'] = u.nums.map(json2.Any(it))
|
||||
mp['lastName'] = u.last_name
|
||||
mp['IsRegistered'] = u.is_registered
|
||||
mp['type'] = u.typ
|
||||
mp['pet_animals'] = u.pets
|
||||
mp['lastName'] = json2.Any(u.last_name)
|
||||
mp['IsRegistered'] = json2.Any(u.is_registered)
|
||||
mp['type'] = json2.Any(u.typ)
|
||||
mp['pet_animals'] = json2.Any(u.pets)
|
||||
return mp.str()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user