Golang encoding/json.RawMessage.UnmarshalJSON function example
package encoding/json
UnmarshalJSON sets *m to a copy of data.
Golang encoding/json.RawMessage.UnmarshalJSON function usage example
func MarshalSlice(in []interface{}) ([]byte, error) {
result := []*json.RawMessage{}
for _, value := range in {
bytes, err := Marshal(value)
if err != nil {
return nil, err
}
message := &json.RawMessage{}
message.UnmarshalJSON(bytes) // <--- here
result = append(result, message)
}
return json.Marshal(result)
}
References :
http://golang.org/pkg/encoding/json/#RawMessage.UnmarshalJSON
Advertisement
Something interesting
Tutorials
+7.5k Golang : Rename part of filename
+5.8k Golang : List all packages and search for certain package
+10.4k Golang : Meaning of omitempty in struct's field tag
+13.4k Golang : Get constant name from value
+4.7k MariaDB/MySQL : Form select statement or search query with Chinese characters
+7.9k Golang : Get today's weekday name and calculate target day distance example
+11.6k SSL : The certificate is not trusted because no issuer chain was provided
+7.7k Golang : Error reading timestamp with GORM or SQL driver
+7.5k Gogland : Single File versus Go Application Run Configurations
+7.2k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+34k Golang : Proper way to set function argument default value
+8.7k Golang : How to join strings?