go - Why Golang cannot generate json from struct with front lowercase character? -
I am trying to print JSON result from the structure created as the following:
Typemachine structure {m_ip string m_type string m_serial string} and print out
m: = & amp; Machine {m_ip: "test", m_type: "test
However, the results simply return {}
second,
type Make Machine Structure {MacIP String MachType string MachSerial string}
And it works! Why is the word with lowercase characters in front work anyway?
uses case to determine whether a specific identifier is public or private in reference to your package In your first example, the fee You do not have to be visible to
json.marshal because it is not part of the package with your code. When you change the fields in the upper case, they can be public so that they can be exported. / P>
If you want to use the following case identifier in your JSON output, you can tag the field with the desired identifier. For example:
type machine Structure {MachIp string `json:" m_ip "` MacType Tring `json:" m_type "` MachSerial string `json:" m_serial "`}
Comments
Post a Comment