Add: JSONObject

This commit is contained in:
dennis 2023-09-11 07:29:39 +08:00
parent fc61b53643
commit b7801dc550

25
JSONObject.go Normal file
View File

@ -0,0 +1,25 @@
package golanghelper
import (
"encoding/json"
)
type JSONObject struct {
Data []byte
}
func NewJSONObject(object interface{}) (jsonObject JSONObject, err error) {
var data []byte
data, err = json.Marshal(object)
if err != nil {
return
}
jsonObject = JSONObject{Data: data}
return
}
func (j *JSONObject) ToString() string {
return string(j.Data)
}