-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Lines 265 to 282 in 7d89f2f
| func encodeStruct(object interface{}, ignoreZero bool) map[string]interface{} { | |
| v := reflect.Indirect(reflect.ValueOf(object)) | |
| t := v.Type() | |
| if v.IsValid() && v.Kind() == reflect.Struct { | |
| encodedMap := make(map[string]interface{}) | |
| for i := 0; i < v.NumField(); i++ { | |
| encodedMap[t.Field(i).Name] = encode(v.Field(i).Interface(), ignoreZero) | |
| if encodedMap[t.Field(i).Name] == nil { | |
| delete(encodedMap, t.Field(i).Name) | |
| } | |
| } | |
| return encodedMap | |
| } | |
| return nil | |
| } |
例如自定一个class 如下:
type Foo struct {
leancloud.Object
Rule struct {
Month int `json:"month"`
Day int `json:"day"`
} `json:"rule"`
}这个Foo对象save以后 rule列应该是 {"month": 1, "day": 1} 而不是{"Month": 1, "Day": 1}
Metadata
Metadata
Assignees
Labels
No labels