From 91eca55f8738b9b8d156e5928d05aaf9e5894f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 12 Oct 2023 18:50:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0struct=20=3D>=20wrapper.Map?= =?UTF-8?q?=E7=9A=84=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- map.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/map.go b/map.go index 7bfc1e1..4de88fe 100644 --- a/map.go +++ b/map.go @@ -12,6 +12,7 @@ import ( "encoding/json" "errors" "git.zhangdeman.cn/zhangdeman/easymap" + "git.zhangdeman.cn/zhangdeman/serialize" "reflect" ) @@ -37,7 +38,11 @@ func EasyMapWithError(mapData interface{}) (Map, error) { m := easymap.NewNormal(true) reflectType := reflect.TypeOf(mapData) if reflectType.Kind() != reflect.Map { - return m, errors.New("input data type is " + reflectType.String() + ", not map") + mapFormatData := make(map[string]interface{}) + if err := serialize.JSON.UnmarshalWithNumber(serialize.JSON.MarshalForByte(mapData), &mapFormatData); nil != err { + return m, errors.New("input data type is " + reflectType.String() + ", can not convert to map") + } + mapData = mapFormatData } reflectValue := reflect.ValueOf(mapData).MapRange()