github.com/gogf/gf@v1.16.9/encoding/gjson/gjson_implements.go (about) 1 // Copyright GoFrame Author(https://goframe.org). 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 7 package gjson 8 9 // MarshalJSON implements the interface MarshalJSON for json.Marshal. 10 func (j *Json) MarshalJSON() ([]byte, error) { 11 return j.ToJson() 12 } 13 14 // UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal. 15 func (j *Json) UnmarshalJSON(b []byte) error { 16 r, err := LoadContent(b) 17 if r != nil { 18 // Value copy. 19 *j = *r 20 } 21 return err 22 } 23 24 // UnmarshalValue is an interface implement which sets any type of value for Json. 25 func (j *Json) UnmarshalValue(value interface{}) error { 26 if r := New(value); r != nil { 27 // Value copy. 28 *j = *r 29 } 30 return nil 31 }