123456789101112131415161718192021222324252627282930313233 |
- package util
- import jsoniter "github.com/json-iterator/go"
- var json = jsoniter.ConfigCompatibleWithStandardLibrary
- func Marshal(v interface{}) ([]byte, error) {
- return json.Marshal(v)
- }
- func MarshalToString(v interface{}) (string, error) {
- return json.MarshalToString(v)
- }
- func Unmarshal(data []byte, v interface{}) error {
- return json.Unmarshal(data, v)
- }
- func MustMarshalToString(v interface{}) string {
- s, _ := json.MarshalToString(v)
- return s
- }
- // 获取args对应的json字符串
- func MarshalJsonString(args ...interface{}) (result string) {
- if len(args) > 0 {
- if r, err := Marshal(args); err == nil {
- result = string(r)
- }
- }
- return
- }
|