json-iterator
第三方库json-iterator
更易用、性能更好的JSON库,与标准库兼容,使用文档参考jsoniter
- 序列化 Marshal
- Marshal
- MarshalToString
- MarshalIndent 美化输出
- 反序列化 Unmarshal
- Unmarshal
- UnmarshalFromString
- Get(data []byte, path …interface{}) Any 获取结构值
- NewDecoder(reader io.Reader) *Decoder 流方式操作JSON大文件
go get github.com/json-iterator/go
// 方便使用的Get方法
val := []byte(`{"ID":1,"Name":"Reds","Colors":["Crimson","Red","Ruby","Maroon"]}`)
jsoniter.Get(val, "Colors", 0).ToString()
jsoniter.MarshalIndent(response, "", " ")
// 与标准库兼容
// internal/json
json := jsoniter.ConfigCompatibleWithStandardLibrary