2025-03-16 18:34:39 +08:00
|
|
|
package common
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func DecodeJson(data []byte, v any) error {
|
|
|
|
|
return json.NewDecoder(bytes.NewReader(data)).Decode(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DecodeJsonStr(data string, v any) error {
|
|
|
|
|
return DecodeJson(StringToByteSlice(data), v)
|
|
|
|
|
}
|
2025-04-10 17:20:59 +08:00
|
|
|
|
|
|
|
|
func EncodeJson(v any) ([]byte, error) {
|
|
|
|
|
return json.Marshal(v)
|
|
|
|
|
}
|