Wednesday, 2 October 2013

Accessing data in nested arrays & objects with Go

Accessing data in nested arrays & objects with Go

I'm doing my best to unmarshall some json data into usable form in Go, but
can't seem to get it. The data is:
{
"series": [
{
"series_id": "PET.EMD_EPD2D_PTE_NUS_DPG.W",
"name": "U.S. No 2 Diesel Retail Prices, Weekly",
"units": "Dollars per Gallon",
"updated": "2013-09-27T07:21:57-0400",
"data": [
[
"20130923",
"3.949"
],
[
"20130916",
"3.974"
]
]
}
]
}
I'm trying to get the arrays under data into a variable, so I can loop
through them and do something like:
if data[i][0] == "20130923" {
fuelPrice.Price == data[i][1]
}
I'm definitely a beginner. Thanks for your time and effort.

No comments:

Post a Comment