json.go 398 B

12345678910111213141516171819202122
  1. package common
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. )
  6. func Unmarshal(data []byte, v any) error {
  7. return json.Unmarshal(data, v)
  8. }
  9. func UnmarshalJsonStr(data string, v any) error {
  10. return json.Unmarshal(StringToByteSlice(data), v)
  11. }
  12. func DecodeJson(reader *bytes.Reader, v any) error {
  13. return json.NewDecoder(reader).Decode(v)
  14. }
  15. func Marshal(v any) ([]byte, error) {
  16. return json.Marshal(v)
  17. }