MCPcopy Index your code
hub / github.com/valyala/fastjson / ExampleValue_Get

Function ExampleValue_Get

parser_example_test.go:83–113  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

81}
82
83func ExampleValue_Get() {
84 s := `{"foo":[{"bar":{"baz":123,"x":"434"},"y":[]},[null, false]],"qwe":true}`
85 var p fastjson.Parser
86 v, err := p.Parse(s)
87 if err != nil {
88 log.Fatalf("cannot parse json: %s", err)
89 }
90
91 vv := v.Get("foo", "0", "bar", "x")
92 fmt.Printf("foo[0].bar.x=%s\n", vv.GetStringBytes())
93
94 vv = v.Get("qwe")
95 fmt.Printf("qwe=%v\n", vv.GetBool())
96
97 vv = v.Get("foo", "1")
98 fmt.Printf("foo[1]=%s\n", vv)
99
100 vv = v.Get("foo").Get("1").Get("1")
101 fmt.Printf("foo[1][1]=%s\n", vv)
102
103 // non-existing key
104 vv = v.Get("foo").Get("bar").Get("baz", "1234")
105 fmt.Printf("foo.bar.baz[1234]=%v\n", vv)
106
107 // Output:
108 // foo[0].bar.x=434
109 // qwe=true
110 // foo[1]=[null,false]
111 // foo[1][1]=false
112 // foo.bar.baz[1234]=<nil>
113}
114
115func ExampleValue_Type() {
116 s := `{

Callers

nothing calls this directly

Calls 4

ParseMethod · 0.95
GetStringBytesMethod · 0.80
GetBoolMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…