|
- package zhios_tool_utils
-
- import (
- "bytes"
- "encoding/json"
- "regexp"
- )
-
- func JsonMarshal(interface{}) {
-
- }
-
- // 不科学计数法
- func JsonDecode(data []byte, v interface{}) error {
- d := json.NewDecoder(bytes.NewReader(data))
- d.UseNumber()
- return d.Decode(v)
- }
-
- // json字符串驼峰命名格式 转为 下划线命名格式
- // c :json字符串
- func MarshalJSONCamelCase2JsonSnakeCase(c string) []byte {
- // Regexp definitions
- var keyMatchRegex = regexp.MustCompile(`\"(\w+)\":`)
- var wordBarrierRegex = regexp.MustCompile(`(\w)([A-Z])`)
- marshalled := []byte(c)
- converted := keyMatchRegex.ReplaceAllFunc(
- marshalled,
- func(match []byte) []byte {
- return bytes.ToLower(wordBarrierRegex.ReplaceAll(
- match,
- []byte(`${1}_${2}`),
- ))
- },
- )
- return converted
- }
|