ObjectToJSONStringFormatted 将对象转换成JSON字符串并格式化
(conf interface{})
| 8 | |
| 9 | // ObjectToJSONStringFormatted 将对象转换成JSON字符串并格式化 |
| 10 | func ObjectToJSONStringFormatted(conf interface{}) string { |
| 11 | b, err := json.Marshal(conf) |
| 12 | if err != nil { |
| 13 | return fmt.Sprintf("%+v", conf) |
| 14 | } |
| 15 | var out bytes.Buffer |
| 16 | err = json.Indent(&out, b, "", " ") |
| 17 | if err != nil { |
| 18 | return fmt.Sprintf("%+v", conf) |
| 19 | } |
| 20 | return out.String() |
| 21 | } |
| 22 | |
| 23 | // ObjectToJSONByte 将对象转换成JSON字节数组 |
| 24 | func ObjectToJSONByte(obj interface{}) []byte { |