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()