增加JSON操作以及map操作
This commit is contained in:
parent
7ed8ccbd87
commit
4a2cf51a9c
29
json.go
29
json.go
@ -46,6 +46,35 @@ func (oj *ownJSON) UnmarshalWithNumberForIOReader(ioReader io.ReadCloser, receiv
|
|||||||
return decoder.Decode(receiver)
|
return decoder.Decode(receiver)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalWithNumberForString 字符串转结构体
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 21:50 2023/7/22
|
||||||
|
func (oj *ownJSON) UnmarshalWithNumberForString(input string, receiver interface{}) error {
|
||||||
|
return oj.UnmarshalWithNumber([]byte(input), receiver)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalForByte 序列化并返回字节数组
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 21:56 2023/7/22
|
||||||
|
func (oj *ownJSON) MarshalForByte(input interface{}) []byte {
|
||||||
|
byteData, _ := json.Marshal(input)
|
||||||
|
return byteData
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalForString 序列化并返回字符串
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 21:56 2023/7/22
|
||||||
|
func (oj *ownJSON) MarshalForString(input interface{}) string {
|
||||||
|
byteData := oj.MarshalForByte(input)
|
||||||
|
return string(byteData)
|
||||||
|
}
|
||||||
|
|
||||||
// ConsoleOutput ...
|
// ConsoleOutput ...
|
||||||
//
|
//
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
13
map.go
13
map.go
@ -214,3 +214,16 @@ func (om *ownMap) GetDataWithReceiver(source map[interface{}]interface{}, key in
|
|||||||
}
|
}
|
||||||
return ConvertAssign(receiver, source[key])
|
return ConvertAssign(receiver, source[key])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToStruct map转结构体
|
||||||
|
//
|
||||||
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
//
|
||||||
|
// Date : 21:48 2023/7/22
|
||||||
|
func (om *ownMap) ToStruct(source map[string]interface{}, receiver interface{}) error {
|
||||||
|
if nil == source {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
byteData := JSON.MarshalForByte(source)
|
||||||
|
return JSON.UnmarshalWithNumber(byteData, receiver)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user