引入 gjson 包
import "github.com/tidwall/gjson"
const good = `{
"name":{
"first":"Janet",
"last":"Prichard"
},
"age":47
}`
const good2 = `{
"name":[{
"first":"Janet",
"last":"Prichard"
}],
"age":47
}`
func main () {
value := gjson.Get(good, "name")
println(value.String())
value := gjson.Get(good2, "name.#.first") // 返回是陣列
for _,val : rang value.Array() {
println(val.String())
}
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結