From febf5a63ad1c94aa879f5da71b34420288388275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 24 Jan 2025 18:48:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E7=BB=93=E6=9E=84=E4=BD=93?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dynamic_struct.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dynamic_struct.go b/dynamic_struct.go index b0961de..db99de2 100644 --- a/dynamic_struct.go +++ b/dynamic_struct.go @@ -8,6 +8,7 @@ package wrapper import ( + "encoding/json" "fmt" "reflect" ) @@ -218,3 +219,12 @@ func (ds *DynamicStruct) Clear() { // 清理掉已设置的字段, 不然实例复用会互相影响 ds.structFieldList = make([]reflect.StructField, 0) } + +// MarshalJSON 自定义的序列化方法 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 18:47 2025/1/24 +func (ds *DynamicStruct) MarshalJSON() ([]byte, error) { + return json.Marshal(ds.mapData) +}