You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

20 lines
380 B

package main
import (
"encoding/json"
)
func main() {
println("int:", encode(3))
println("float64:", encode(3.14))
println("string:", encode("foo"))
println("slice of strings:", encode([]string{"foo", "bar"}))
}
func encode(itf interface{}) string {
buf, err := json.Marshal(itf)
if err != nil {
panic("failed to JSON encode: " + err.Error())
}
return string(buf)
}