forked from goplus/llgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkjson.go
43 lines (31 loc) · 774 Bytes
/
mkjson.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/cjson"
)
func main() {
mod := cjson.Object()
mod.SetItem(c.Str("name"), cjson.String(c.Str("math")))
syms := cjson.Array()
fn := cjson.Object()
fn.SetItem(c.Str("name"), cjson.String(c.Str("sqrt")))
fn.SetItem(c.Str("sig"), cjson.String(c.Str("(x, /)")))
syms.AddItem(fn)
v := cjson.Object()
v.SetItem(c.Str("name"), cjson.String(c.Str("pi")))
syms.AddItem(v)
mod.SetItem(c.Str("items"), syms)
cstr := mod.CStr()
str := c.GoString(cstr)
c.Printf(c.Str("%s\n"), cstr)
cjson.FreeCStr(cstr)
mod.Delete()
cjsonLoad(str)
}
func cjsonLoad(str string) {
mod := cjson.ParseString(str)
cstr := mod.Print()
c.Printf(c.Str("%s\n"), cstr)
cjson.FreeCStr(cstr)
mod.Delete()
}