github.com/gogf/gf@v1.16.9/encoding/gjson/gjson_z_example_load_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package gjson_test 8 9 import ( 10 "fmt" 11 "github.com/gogf/gf/debug/gdebug" 12 "github.com/gogf/gf/encoding/gjson" 13 ) 14 15 func Example_loadJson() { 16 jsonFilePath := gdebug.TestDataPath("json", "data1.json") 17 j, _ := gjson.Load(jsonFilePath) 18 fmt.Println(j.Get("name")) 19 fmt.Println(j.Get("score")) 20 } 21 22 func Example_loadXml() { 23 jsonFilePath := gdebug.TestDataPath("xml", "data1.xml") 24 j, _ := gjson.Load(jsonFilePath) 25 fmt.Println(j.Get("doc.name")) 26 fmt.Println(j.Get("doc.score")) 27 } 28 29 func Example_loadContent() { 30 jsonContent := `{"name":"john", "score":"100"}` 31 j, _ := gjson.LoadContent(jsonContent) 32 fmt.Println(j.Get("name")) 33 fmt.Println(j.Get("score")) 34 // Output: 35 // john 36 // 100 37 }