package main
import (
"encoding/json"
"fmt"
)
type InnerData struct {
M int64 `josn:"m"`
N int64 `json:"n"`
}
//JSONData is a json data example
type JSONData struct {
Hello string `json:"hello"`
Data InnerData `json:"data"`
}
func main() {
v := JSONData{Hello: "world", Data: InnerData{N: 100000, M: 123456}}
mashaled, err := json.Marshal(&v)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(mashaled))
}
Noted the field M in InnerData has a tag m, so the expected result is :{"hello":"world","data":{"m":123456,"n":100000}}. While I have
{"hello":"world","data":{"M":123456,"n":100000}}
Does anyone know how to fix the problem, or where am I wrong?