github.com/zhongdalu/gf@v1.0.0/g/encoding/gjson/gjson_api_encoding.go (about) 1 // Copyright 2017 gf Author(https://github.com/zhongdalu/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/zhongdalu/gf. 6 7 package gjson 8 9 import ( 10 "encoding/json" 11 "github.com/zhongdalu/gf/g/encoding/gtoml" 12 "github.com/zhongdalu/gf/g/encoding/gxml" 13 "github.com/zhongdalu/gf/g/encoding/gyaml" 14 ) 15 16 func (j *Json) ToXml(rootTag ...string) ([]byte, error) { 17 return gxml.Encode(j.ToMap(), rootTag...) 18 } 19 20 func (j *Json) ToXmlString(rootTag ...string) (string, error) { 21 b, e := j.ToXml(rootTag...) 22 return string(b), e 23 } 24 25 func (j *Json) ToXmlIndent(rootTag ...string) ([]byte, error) { 26 return gxml.EncodeWithIndent(j.ToMap(), rootTag...) 27 } 28 29 func (j *Json) ToXmlIndentString(rootTag ...string) (string, error) { 30 b, e := j.ToXmlIndent(rootTag...) 31 return string(b), e 32 } 33 34 func (j *Json) ToJson() ([]byte, error) { 35 j.mu.RLock() 36 defer j.mu.RUnlock() 37 return Encode(*(j.p)) 38 } 39 40 func (j *Json) ToJsonString() (string, error) { 41 b, e := j.ToJson() 42 return string(b), e 43 } 44 45 func (j *Json) ToJsonIndent() ([]byte, error) { 46 j.mu.RLock() 47 defer j.mu.RUnlock() 48 return json.MarshalIndent(*(j.p), "", "\t") 49 } 50 51 func (j *Json) ToJsonIndentString() (string, error) { 52 b, e := j.ToJsonIndent() 53 return string(b), e 54 } 55 56 func (j *Json) ToYaml() ([]byte, error) { 57 j.mu.RLock() 58 defer j.mu.RUnlock() 59 return gyaml.Encode(*(j.p)) 60 } 61 62 func (j *Json) ToYamlString() (string, error) { 63 b, e := j.ToYaml() 64 return string(b), e 65 } 66 67 func (j *Json) ToToml() ([]byte, error) { 68 j.mu.RLock() 69 defer j.mu.RUnlock() 70 return gtoml.Encode(*(j.p)) 71 } 72 73 func (j *Json) ToTomlString() (string, error) { 74 b, e := j.ToToml() 75 return string(b), e 76 }