mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
39 lines
944 B
Go
39 lines
944 B
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package gjson_test
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gogf/gf/v2/debug/gdebug"
|
|
"github.com/gogf/gf/v2/encoding/gjson"
|
|
)
|
|
|
|
func Example_loadJson() {
|
|
jsonFilePath := gdebug.TestDataPath("json", "data1.json")
|
|
j, _ := gjson.Load(jsonFilePath)
|
|
fmt.Println(j.Get("name"))
|
|
fmt.Println(j.Get("score"))
|
|
}
|
|
|
|
func Example_loadXml() {
|
|
jsonFilePath := gdebug.TestDataPath("xml", "data1.xml")
|
|
j, _ := gjson.Load(jsonFilePath)
|
|
fmt.Println(j.Get("doc.name"))
|
|
fmt.Println(j.Get("doc.score"))
|
|
}
|
|
|
|
func Example_loadContent() {
|
|
jsonContent := `{"name":"john", "score":"100"}`
|
|
j, _ := gjson.LoadContent(jsonContent)
|
|
fmt.Println(j.Get("name"))
|
|
fmt.Println(j.Get("score"))
|
|
// Output:
|
|
// john
|
|
// 100
|
|
}
|