JSON Response Data Troubles

Greetings and happy friday!

I’m trying to get to the nested data within the JSON response, but i’m obviously missing something. My struct looks like …

type MyInformation struct {
	MyResults []struct {
		MoreData []struct {
			Name    string          `json:"name"`
			Tags    interface{}     `json:"tags"`
			Columns []string        `json:"columns"`
			Values  [][]interface{} `json:"values"`
		} `json:"moredata"`
	} `json:"myresults"`
}

If i have …

//
var myResponseData []MyInformation
//
for i := range myResponseData {
		fmt.Fprintf(myOutputData, "%v\n", myResponseData[i].MyResults)
}

I can see MyResults, but i can’t seem to see anything else (particularly “Values”). Any thoughts?

Thanks in advance!

T

type MyInformation struct {
    MyResults []struct {
        MoreData []struct {
            Name string json:"name"
            Tags interface{} json:"tags"
            Columns []string json:"columns"
            Values [][]interface{} json:"values"
         } json:"moredata"
    } json:"myresults"
}

//
var myResponseData []MyInformation
//
for i := range myResponseData {
    fmt.Fprintf(myOutputData, “%v\n”, myResponseData[i].MyResults)
}

I don’t think you should be using empty interfaces for any of this. You should try with slice of strings for your tags probably, and whatever type for the values you expect to receive.

Thank you for the kind response!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.