mirror of
https://gitee.com/johng/gf
synced 2026-06-07 10:22:11 +08:00
39 lines
1003 B
Go
39 lines
1003 B
Go
|
|
// Copyright 2017 gf Author(https://github.com/gogf/gf). 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/debug/gdebug"
|
||
|
|
"github.com/gogf/gf/encoding/gjson"
|
||
|
|
"github.com/gogf/gf/os/gfile"
|
||
|
|
)
|
||
|
|
|
||
|
|
func Example_LoadJson() {
|
||
|
|
jsonFilePath := gfile.Join(gdebug.TestDataPath(), "json", "data1.json")
|
||
|
|
j, _ := gjson.Load(jsonFilePath)
|
||
|
|
fmt.Println(j.Get("name"))
|
||
|
|
fmt.Println(j.Get("score"))
|
||
|
|
}
|
||
|
|
|
||
|
|
func Example_LoadXml() {
|
||
|
|
jsonFilePath := gfile.Join(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
|
||
|
|
}
|