gjson_implements.go 843 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. package gjson
  7. // MarshalJSON implements the interface MarshalJSON for json.Marshal.
  8. func (j *Json) MarshalJSON() ([]byte, error) {
  9. return j.ToJson()
  10. }
  11. // UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
  12. func (j *Json) UnmarshalJSON(b []byte) error {
  13. r, err := LoadContent(b)
  14. if r != nil {
  15. // Value copy.
  16. *j = *r
  17. }
  18. return err
  19. }
  20. // UnmarshalValue is an interface implement which sets any type of value for Json.
  21. func (j *Json) UnmarshalValue(value interface{}) error {
  22. if r := New(value); r != nil {
  23. // Value copy.
  24. *j = *r
  25. }
  26. return nil
  27. }