package
0.0.0-20240826130101-256bcdb5d6a2
Repository: https://github.com/3th1nk/easygo.git
Documentation: pkg.go.dev

# README

对 json-iterator 的封装

  • 默认开启 “弱类型解析”
    • 比如一个字段声明的是 Id int,但 json 字符串中格式为 "id": "123",仍然能够成功的将其解析为 Id=int(123)。其他类型同理。
  • 针对常用的场景,对函数做了封装

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
注册加密字段。 加密字段会使用 AES 加密算法在 JSON 序列化和反序列化时自动加解密。.
注册接口类型的序列化与反序列化逻辑。 默认情况下无法将 JSON 字符串反序列化到接口对象中,因为持续不知道对应的具体的类型。 InterfaceCodec 通过在序列化时通过额外的字段把具体的类型信息也序列化到 JSON 字符串中,这样在反序列化时候就能够通过类型名称创建不同类型的对象。 Example: type testA struct { AAA int `json:"aaa,omitempty"` } type testB struct { BBB int `json:"bbb,omitempty"` } func (this *testA) getType() string { return "a" } func (this *testB) getType() string { return "b" } type testStruct struct { Obj testInterface `json:"obj,omitempty"` } type testInterface interface { getType() string } a := &testStruct{ Obj: &testA{ AAA: 111}, } util.Println(MustMarshalToString(a)) // {"obj":{"type":"a","data":{"aaa":111}}} b := &testStruct{ Obj: &testB{BBB: 222}, } util.Println(MustMarshalToString(b)) // {"obj":{"type":"b","data":{"bbb":222}}}.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author

# Structs

------------------------------------------------------------------------------ Api.
接口类型的编解码选项。 Type: 接口类型 TypeField: 序列化时用来存储类型名称的字段 DataField: 序列化时用来存储数据的字段 Encode: 序列化方法,指定接口对象、返回具体的类型名称和数据对象。 Decode: 反序列化方法,通过类型名称和数据对象返回接口对象。.