2025-03-16 18:34:39 +08:00
|
|
|
package common
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
)
|
|
|
|
|
|
2025-07-10 15:02:40 +08:00
|
|
|
func Unmarshal(data []byte, v any) error {
|
2025-06-28 00:02:07 +08:00
|
|
|
return json.Unmarshal(data, v)
|
2025-03-16 18:34:39 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-28 00:02:07 +08:00
|
|
|
func UnmarshalJsonStr(data string, v any) error {
|
|
|
|
|
return json.Unmarshal(StringToByteSlice(data), v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DecodeJson(reader *bytes.Reader, v any) error {
|
|
|
|
|
return json.NewDecoder(reader).Decode(v)
|
2025-03-16 18:34:39 +08:00
|
|
|
}
|
2025-04-10 17:20:59 +08:00
|
|
|
|
2025-07-10 15:02:40 +08:00
|
|
|
func Marshal(v any) ([]byte, error) {
|
2025-04-10 17:20:59 +08:00
|
|
|
return json.Marshal(v)
|
|
|
|
|
}
|