Hi,
I’m working on parsing out nested json data and I’m seeing an odd result. I’m getting the product description, but not the product name or location in print statements. Any help would be appreciated.
tempDevs := myDevs.DevInstances
for _, dev := range tempDevs {
fmt.Printf("serialNumber = %s\n",dev.SerialNumber)
fmt.Printf("ProductName = %s\n",dev.Product.PName)
fmt.Printf("ProductNumber = %s\n",dev.Product.PNumber)
fmt.Printf("ProductDescription = %s\n",dev.Product.PDescription)
fmt.Printf("Location = %s\n",dev.Product.PLocation)
fmt.Printf("\n")
}
here is a sample of the formatting:
‘’’{“totalRecords”:2,“instances”:[{“serialNumber”:“testSN1”,“parentSerialNumber”:“anotherSN”,“minor”:false,“instanceNumber”:“8765345678”,“installedBaseStatus”:“Latest-INSTALLED”,“endCustomer”:{“id”:“1”,“name”:“test client”,“address”:{“address1”:“100 myStreet”,“city”:“Albany”,“country”:“US”,“state”:“NY”,“postalCode”:“12345”}},“serviceSKU”:“testSKU1”,“serviceLevel”:“SL1”,“serviceDescription”:“testdesc1”,“startDate”:“2018-04-09T00:00:00Z”,“endDate”:“2019-04-08T00:00:00Z”,“product”:{“number”:“productNumber1”,“description”:“test product desc”,“family”:“fam1”,“group”:“group1”,“location”:“80616”,“name”:“test product name”},
‘’’
here are the structs I’m building out:
‘’’
type DeviceInstances struct {
SerialNumber string json:"serialNumber"
ParentSerialNumber string json:"parentSerialNumber"
Minor bool json:"minor"
InstanceNumber string json:"instanceNumber"
InstalledBaseStatus string json:"installedBaseStatus"
ServiceSKU string json:"serviceSKU"
ServiceLevel string json:"serviceLevel"
ServiceDescription string json:"serviceDescription"
StartDate string json:"startDate"
EndDate string json:"endDate"
MacId string json:"macId"
CartonId string json:"cartonId"
Quantity int json:"quantity"
SalesOrderNumber string json:"salesOrderNumber"
PurchaseOrderNumber string json:"purchaseOrderNumber"
MaintenanceSalesOrderNumber string json:"maintenanceSalesOrderNumber"
MaintenancePurchaseOrderNumber string json:"maintenancePurchaseOrderNumber"
ItemType string json:"itemType"
ShipDate string json:"shipDate"
Product DeviceProduct json:"product"
}
type DeviceProduct struct {
PName string json:"name"
PNumber string json:"number"
PDescription string json:"description"
PLocation string json:"location"
}
‘’’