Here is my situation, i requested to a server with a GET and received a JSON format. i'm using go lang, and implemented it in Go Lang in beego web framework.
So i have implemented it like this one,
func (d *Tom) Get() {
//passengersFile, err := http.Get("https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&apikey=KLMH2VFJ0LCFNOX5")
resp, err := http.Get("https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&apikey=KLMH2VF0LCFNOX5")
if err != nil {
panic(err)
}
defer resp.Body.Close()
//fmt.Printf("%#v
", resp)
dec := json.NewDecoder(resp.Body)
if dec == nil {
panic("Failed to start decoding JSON data")
}
json_map := make(map[string]interface{})
err = dec.Decode(&json_map)
for k, v := range json_map {
if k == "Meta Data"{
continue
}
fmt.Printf("key[%s] value[%s]
", k, v)
}
if err != nil {
panic(err)
}
d.Data["json"] = &json_map
d.ServeJSON()
}
the format of the incoming json is like that ....
{
"Meta Data": {
"1. Information": "Intraday (1min) prices and volumes",
"2. Symbol": "MSFT",
"3. Last Refreshed": "2018-05-25 09:31:00",
"4. Interval": "1min",
"5. Output Size": "Compact",
"6. Time Zone": "US/Eastern"
},
"Time Series (1min)": {
"2018-05-24 14:23:00": {
"1. open": "98.1432",
"2. high": "98.1661",
"3. low": "98.1238",
"4. close": "98.1500",
"5. volume": "19106"
},
"2018-05-24 14:24:00": {
"1. open": "98.1500",
"2. high": "98.1700",
"3. low": "98.1400",
"4. close": "98.1650",
"5. volume": "18279"
},
"2018-05-24 14:25:00": {
"1. open": "98.1650",
"2. high": "98.2000",
"3. low": "98.1600",
"4. close": "98.1900",
"5. volume": "32085"
}
}
}
Now i want to get the "Time Series (1min)" values and iterate on them to get each value of the "Date Time" values, like "1. open" ... etc. And of course save them on a single json and return it for those who requested it. Any help will be greatly appreciated!