how to serialize/deserialize a map in go

前端 未结 2 1785
清歌不尽
清歌不尽 2021-02-07 07:07

My instinct tells me that somehow it would have to be converted to a string or byte[] (which might even be the same things in Go?) and then saved to disk.

I found this

2条回答
  •  没有蜡笔的小新
    2021-02-07 07:59

    The gob package will let you serialize maps. I wrote up a small example http://play.golang.org/p/6dX5SMdVtr demonstrating both encoding and decoding maps. Just as a heads up, the gob package can't encode everything, such as channels.

    Edit: Also string and []byte are not the same in Go.

提交回复
热议问题