go - How to fetch values from JSON in golang -


i have following piece of code calls yahoo finance api stock values given stock symbol.

package main  import (     "encoding/json"     "fmt"     "io/ioutil"     "net/http"     "os" )  //response structure type response struct {     query struct {         count   int    `json:"count"`         created string `json:"created"`         lang    string `json:"lang"`         results struct {             quote []struct {                 lasttradepriceonly string `json:"lasttradepriceonly"`             } `json:"quote"`         } `json:"results"`     } `json:"query"` }  func main() {     var s response     response, err := http.get("http://query.yahooapis.com/v1/public/yql?q=select%20lasttradepriceonly%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%22aapl%22,%22fb%22)&format=json&env=store%3a%2f%2fdatatables.org%2falltableswithkeys")     if err != nil {         fmt.printf("%s", err)         os.exit(1)     } else {         defer response.body.close()          contents, err := ioutil.readall(response.body)         json.unmarshal([]byte(contents), &s)         fmt.println(s.query.results.quote)          if err != nil {             fmt.printf("%s", err)             os.exit(1)         }         fmt.printf("%s\n", string(contents))     } } 

fmt.println(s.query.results.quote) giving me multi value array since quote array of structure. eg: [{52.05},{114.25}] how should split in single value in golang ? eg: 52.05 114.25

help highly appreciated. thanks

i new golang , not aware of many data structures. figured out how single value out of array of structure.

fmt.println(s.query.results.quote[0].lasttradepriceonly) 

this worked me..i have iterate in loop fetch values.

thanks.


Comments