一、gojsonp简介
二、常规用法
https://github.com/thedevsaddam/gojsonq
三、经典用法
1、取出json array符合条件的一组元素的某一个值
[ { "showName":"提交申请", "showNameEn":"Submit", "remark":"" }, { "showName":"审核", "showNameEn":"managerApproval", "remark":"Disagree" } ]
取showNameEn为managerApproval所在remark内容
package main import ( "fmt" "github.com/thedevsaddam/gojsonq" ) func main() { const json = `[{"showName":"提交申请","showNameEn":"Submit","remark":""},{"showName":"审核","showNameEn":"managerApproval", "remark":"Disagree"}]` infos := gojsonq.New().JSONString(json).Where("showNameEn", "=", "managerApproval").Get() var interfaceSlice []interface{} = make([]interface{}, 0) interfaceSlice := infos.([]interface{}) info := interfaceSlice[0].(map[string]interface{}) fmt.Printf("%#v", info["remark"]) }
参考:
Golang 从 Json 串中快速取出需要的字段【CSDN的文章,不用细看】