github.com/zhongdalu/gf@v1.0.0/g/encoding/gparser/gparser_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://gitee.com/johng/gp. 6 7 package gparser 8 9 // MarshalJSON implements the interface MarshalJSON for json.Marshal. 10 func (p *Parser) MarshalJSON() ([]byte, error) { 11 return p.json.MarshalJSON() 12 } 13 14 func (p *Parser) ToXml(rootTag ...string) ([]byte, error) { 15 return p.json.ToXml(rootTag...) 16 } 17 18 func (p *Parser) ToXmlIndent(rootTag ...string) ([]byte, error) { 19 return p.json.ToXmlIndent(rootTag...) 20 } 21 22 func (p *Parser) ToJson() ([]byte, error) { 23 return p.json.ToJson() 24 } 25 26 func (p *Parser) ToJsonString() (string, error) { 27 return p.json.ToJsonString() 28 } 29 30 func (p *Parser) ToJsonIndent() ([]byte, error) { 31 return p.json.ToJsonIndent() 32 } 33 34 func (p *Parser) ToJsonIndentString() (string, error) { 35 return p.json.ToJsonIndentString() 36 } 37 38 func (p *Parser) ToYaml() ([]byte, error) { 39 return p.json.ToYaml() 40 } 41 42 func (p *Parser) ToToml() ([]byte, error) { 43 return p.json.ToToml() 44 } 45 46 func VarToXml(value interface{}, rootTag ...string) ([]byte, error) { 47 return New(value).ToXml(rootTag...) 48 } 49 50 func VarToXmlIndent(value interface{}, rootTag ...string) ([]byte, error) { 51 return New(value).ToXmlIndent(rootTag...) 52 } 53 54 func VarToJson(value interface{}) ([]byte, error) { 55 return New(value).ToJson() 56 } 57 58 func VarToJsonString(value interface{}) (string, error) { 59 return New(value).ToJsonString() 60 } 61 62 func VarToJsonIndent(value interface{}) ([]byte, error) { 63 return New(value).ToJsonIndent() 64 } 65 66 func VarToJsonIndentString(value interface{}) (string, error) { 67 return New(value).ToJsonIndentString() 68 } 69 70 func VarToYaml(value interface{}) ([]byte, error) { 71 return New(value).ToYaml() 72 } 73 74 func VarToToml(value interface{}) ([]byte, error) { 75 return New(value).ToToml() 76 } 77 78 func VarToStruct(value interface{}, obj interface{}) error { 79 return New(value).ToStruct(obj) 80 }