在Golang中,可以使用github.com/tidwall/gjson
包来根据JSON路径提取字段值。
package main import ( "fmt" "github.com/tidwall/gjson" ) func main() { jsonStr := ` { "name": "John", "age": 30, "city": "New York" } ` // 提取name字段的值 name := gjson.Get(jsonStr, "name") fmt.Println(name.String()) // 提取age字段的值 age := gjson.Get(jsonStr, "age") fmt.Println(age.Int()) // 提取city字段的值 city := gjson.Get(jsonStr, "city") fmt.Println(city.String()) }
https://github.com/tidwall/gjson
https://blog.csdn.net/finghting321/article/details/105655960/
标签:jsonStr,段值,gjson,name,city,age,golang,json,fmt From: https://www.cnblogs.com/ExMan/p/17853949.html