Browse Source

加入interface转map[string]string

master v0.2.8
listen 2 years ago
parent
commit
a200850a57
1 changed files with 37 additions and 10 deletions
  1. +37
    -10
      map.go

+ 37
- 10
map.go View File

@ -97,32 +97,59 @@ func MapStringToInterface(src map[string]string) map[string]interface{} {
} }
//将interface转成map[string]interface //将interface转成map[string]interface
func InterfaceToMapInterface(data interface{})(map[string]interface{},error){
dataJson,err := json.Marshal(data)
func InterfaceToMapInterface(data interface{}) (map[string]interface{}, error) {
dataJson, err := json.Marshal(data)
if err != nil { if err != nil {
return nil,err
return nil, err
} }
var returnData map[string]interface{} var returnData map[string]interface{}
err = json.Unmarshal(dataJson,&returnData)
err = json.Unmarshal(dataJson, &returnData)
return returnData,nil
return returnData, nil
} }
//将interface转成map[string]string
func InterfaceToMapString(data interface{}) (map[string]string, error) {
dataJson, err := json.Marshal(data)
if err != nil {
return nil, err
}
var returnData map[string]string
err = json.Unmarshal(dataJson, &returnData)
return returnData, nil
}
//将interface转成[]map[string]interface //将interface转成[]map[string]interface
func InterfaceToMapInterfaceArr(data interface{})([]map[string]interface{},error){
dataJson,err := json.Marshal(data)
func InterfaceToMapInterfaceArr(data interface{}) ([]map[string]interface{}, error) {
dataJson, err := json.Marshal(data)
if err != nil { if err != nil {
return nil,err
return nil, err
} }
var returnData []map[string]interface{} var returnData []map[string]interface{}
err = json.Unmarshal(dataJson,&returnData)
err = json.Unmarshal(dataJson, &returnData)
return returnData, nil
}
//将interface转成[]map[string]string
func InterfaceToMapStringArr(data interface{}) ([]map[string]string, error) {
dataJson, err := json.Marshal(data)
if err != nil {
return nil, err
}
var returnData []map[string]string
err = json.Unmarshal(dataJson, &returnData)
return returnData,nil
return returnData, nil
} }
/** /**


Loading…
Cancel
Save