Skip to content

Instantly share code, notes, and snippets.

@kazken3
Created June 4, 2020 14:47
Show Gist options
  • Save kazken3/aad067bd712821ddd8d56230c28eca2a to your computer and use it in GitHub Desktop.
Save kazken3/aad067bd712821ddd8d56230c28eca2a to your computer and use it in GitHub Desktop.
json by float
package main
import (
"encoding/json"
)
type Test struct {
Id string `json:"id"`
Specs []Spec `json:"spec"`
}
type Spec struct {
Vid uint `json:"vid"`
X float32 `json:"x"`
Y float64 `json:"y"`
Z float64 `json:"z"`
}
func main() {
spec := Spec{Vid:1,X:1.2345, Y:9.876, Z:-1.2345}
test := Test{Id:"1",Specs:[]Spec{spec}}
json, err := json.Marshal(test)
if err != nil{
println("Marshal err",err)
return
}
println(string(json))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment