38 lines
1.4 KiB
Go
38 lines
1.4 KiB
Go
package main
|
||
|
||
import (
|
||
"fmt"
|
||
"github.com/tidwall/gjson"
|
||
)
|
||
|
||
func main() {
|
||
exampleJsonString := `{
|
||
"code":"000",
|
||
"data":{
|
||
"all_count":441353,
|
||
"lists":[
|
||
{
|
||
"id":441353,
|
||
"job_name":"经营日报-同步职位信息",
|
||
"job_recall_time":"2021-03-13 15:05:04",
|
||
"job_recall_content":"请求成功:great",
|
||
"create_time":"2021-03-13 15:05:04"
|
||
},
|
||
{
|
||
"id":441352,
|
||
"job_name":"经营日报-Check张继学列表",
|
||
"job_recall_time":"2021-03-13 15:05:00",
|
||
"job_recall_content":"请求成功:OK",
|
||
"create_time":"2021-03-13 15:05:00"
|
||
}
|
||
]
|
||
},
|
||
"msg":"获取列表成功",
|
||
"success":true
|
||
}`
|
||
jsonCode := gjson.Get(exampleJsonString, "code") //这个后面你可以继续跟想要的结果类型,不加的话会是json字符串的类型
|
||
fmt.Println(jsonCode) // 结果 000
|
||
jsonOneJobName := gjson.Get(exampleJsonString, "data.lists.#.job_name").Array() //比如我这里就希望返回是一个切片类型
|
||
fmt.Println(jsonOneJobName) // 结果 [经营日报-同步职位信息 经营日报-Check张继学列表]
|
||
}
|