Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

package main
import ( "encoding/json" "fmt" "github.com/gogf/gf/container/garray" ) func main() { type Student struct { Id int Name string Scores *garray.IntArray } s := Student{ Id: 1, Name: "john", Scores: garray.NewIntArrayFrom([]int{100, 99, 98}), } b, _ := json.Marshal(s) fmt.Println(string(b)) }

执行后,输出结果:```

Code Block
languagego
 {"Id":1,"Name":"john","Scores":[100,99,98]}

...

 


  1. Unmarshal
package main


import (
    "encoding/json"
    "fmt"
    "github.com/gogf/gf/container/garray"
)


func main() {
    b := []byte(`{"Id":1,"Name":"john","Scores":[100,99,98]}`)
    type Student struct {
        Id     int
        Name   string
        Scores *garray.IntArray
    }
    s := Student{}
    json.Unmarshal(b, &s)
    fmt.Println(s)
}

...