github.com/qiniu/x@v1.11.9/jsonutil/json_string.go (about) 1 package jsonutil 2 3 import ( 4 "encoding/json" 5 "reflect" 6 "unsafe" 7 ) 8 9 // ---------------------------------------------------------- 10 11 // Unmarshal parses the JSON-encoded data and stores the result in the value pointed to by v. 12 func Unmarshal(data string, v interface{}) error { 13 14 sh := *(*reflect.StringHeader)(unsafe.Pointer(&data)) 15 arr := (*[1 << 30]byte)(unsafe.Pointer(sh.Data)) 16 return json.Unmarshal(arr[:sh.Len], v) 17 } 18 19 // ---------------------------------------------------------- 20 21 // Stringify converts a value into string. 22 func Stringify(v interface{}) string { 23 b, _ := json.Marshal(v) 24 return string(b) 25 } 26 27 // ----------------------------------------------------------