From 4e24f1a655c69716adf64d1314880f9ab6d6bcb0 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, 2 Jun 2023 16:43:18 +0800 Subject: [PATCH] to struct --- object.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/object.go b/object.go index 8bebd85..e7572c7 100644 --- a/object.go +++ b/object.go @@ -115,3 +115,33 @@ func (ot *ObjectType) ToMapStringAny() ObjectResult { res.Err = util.JSON.UnmarshalWithNumber(ot.byteData, &res.Value) return res } + +// ToStruct ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 16:41 2023/6/2 +func (ot *ObjectType) ToStruct(receiver interface{}) error { + if nil == receiver { + return errors.New("receiver is nil") + } + if ot.IsNil() { + return errors.New("data is nil") + } + return util.JSON.UnmarshalWithNumber(ot.byteData, receiver) +} + +// ToStructIgnoreErr ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 16:42 2023/6/2 +func (ot *ObjectType) ToStructIgnoreErr(receiver interface{}) { + if nil == receiver { + return + } + if ot.IsNil() { + return + } + _ = util.JSON.UnmarshalWithNumber(ot.byteData, receiver) +}