1. 项目地址:
    https://github.com/Jeffail/gabs
  2. 用法:
    1. 生成:
      package main
      import (
      "fmt"
      "github.com/Jeffail/gabs/v2"
      )
      func main() {
      data := map[string]interface{}{
       "code": 1,
       "msg": "成功",
       "data": []int{
           1,2,3,
       },
      }
      jsonObj := gabs.New()
      jsonObj.Set(data,"data")
      output := jsonObj.String()
      fmt.Println(output)
      }
      // 输出
      {"data":{"code":1,"data":[1,2,3],"msg":"成功"}}
    2. 解析:
      package main
      import (
      "fmt"
      "github.com/Jeffail/gabs/v2"
      )
      func main() {
      json := `{"data":{"code":1,"data":[1,2,3],"msg":"成功","obj":{"name":"lee","height":"168"}}}`
      jsonParsed, _ := gabs.ParseJSON([]byte(json))
      code, _ := jsonParsed.Search("data", "code").Data().(float64)
      msg, _ := jsonParsed.Search("data", "msg").Data().(string)
      fmt.Println(code,msg)
      for _, child := range jsonParsed.S("data","data").Children() {
       fmt.Println(child.Data().(float64))
      }
      for key, child := range jsonParsed.S("data","obj").ChildrenMap() {
       fmt.Println(key, child.Data().(string))
      }
      }
      // 输出
      1 成功
      1
      2
      3
      name lee
      height 168
文档更新时间: 2020-10-23 09:26   作者:lee