studyGo/hello.go
2021-07-11 23:03:35 +08:00

38 lines
1.4 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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张继学列表]
}