I pick up JSON from a third-party site (using home consumption), and depending on what I requested on the site, the returned JSON may or may not be an array. For example, if I request a list of my smart meters, I get this (results are truncated due to the large size):
{"gwrcmds":{"gwrcmd":{"gcmd":"SPA_UserGetSmartMeterList","gdata":{"gip":{"version":"1"...
Where gwrcmd is one element.
But if I ask for the use of electricity in the last hour and a half, I get the following:
{"gwrcmds":{"gwrcmd":[{"gcmd":"DeviceGetChart","gdata":{"gip":{"version":"1" ...
See how gwrcmd is now an array?
In my Go app, I have a structure that looks like this (again, truncated as it has been going on for some time). There are more substructures and properties below the "Version":
type Response struct {
Gwrcmds struct {
Gwrcmd struct {
Gcmd string
Gdata struct {
Gip struct {
Version string
gwrcmd - , gwrcmd []struct { }, , struct { }
, json.Unmarshal , JSON , ( ).
, ( []struct { }), ? - , , 100%.