FAQ
I just started working with go and its a simple question for all of you.
This is the struct i have and i am able to unmarshal some data that i have,
into this. I am having trouble iterating over the struct.

type resultSet struct {

        Results []struct {

                 Series []struct {

                         Columns []string `json:"columns"`

                         Name string `json:"name"`

                         Values [][]string `json:"values"`

                 } `json:"series"`

         } `json:"results"`

}

         for _, c := range ss.Results[0].Series {

                         fmt.Println(c.Name)

                 for j, d := range c.Values {

                         fmt.Println(d[0][j])

                 }

         }

Can't seem to get the 'values' out. Thanks for the help.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Caleb Spare at Mar 31, 2015 at 9:20 pm
    Can you show some of the data that you are unmarshaling?

    It would also help if you can attach a link to a runnable example on
    play.golang.org, or at least give the error you're encountering. I'm not
    sure what "Can't seem to get the 'values' out" means.

    -Caleb
    On Tue, Mar 31, 2015 at 11:41 AM, wrote:

    I just started working with go and its a simple question for all of you.
    This is the struct i have and i am able to unmarshal some data that i
    have, into this. I am having trouble iterating over the struct.

    type resultSet struct {

    Results []struct {

    Series []struct {

    Columns []string `json:"columns"`

    Name string `json:"name"`

    Values [][]string `json:"values"`

    } `json:"series"`

    } `json:"results"`

    }

    for _, c := range ss.Results[0].Series {

    fmt.Println(c.Name)

    for j, d := range c.Values {

    fmt.Println(d[0][j])

    }

    }

    Can't seem to get the 'values' out. Thanks for the help.

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Charles Haynes at Mar 31, 2015 at 9:52 pm
    d[0][j] is wrong. j is an index into d. you need to add another range over
    d. You're indexing into the first component of Values using the number of
    top level components, not the number of elements of that compoonent.

    http://play.golang.org/p/IkZ3uTuyCS

    -- Charles
    On Wed, Apr 1, 2015 at 8:20 AM, Caleb Spare wrote:

    Can you show some of the data that you are unmarshaling?

    It would also help if you can attach a link to a runnable example on
    play.golang.org, or at least give the error you're encountering. I'm not
    sure what "Can't seem to get the 'values' out" means.

    -Caleb
    On Tue, Mar 31, 2015 at 11:41 AM, wrote:

    I just started working with go and its a simple question for all of you.
    This is the struct i have and i am able to unmarshal some data that i
    have, into this. I am having trouble iterating over the struct.

    type resultSet struct {

    Results []struct {

    Series []struct {

    Columns []string `json:"columns"`

    Name string `json:"name"`

    Values [][]string `json:"values"`

    } `json:"series"`

    } `json:"results"`

    }

    for _, c := range ss.Results[0].Series {

    fmt.Println(c.Name)

    for j, d := range c.Values {

    fmt.Println(d[0][j])

    }

    }

    Can't seem to get the 'values' out. Thanks for the help.

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Raju Srini at Mar 31, 2015 at 10:18 pm
    Thanks Charles. I should have provided more informaiton. But this is what i
    was missing:

    *for j := range d {*
    * fmt.Println(d[j])*
    *}*

    Thanks for your help.

    Thanks,
    Srini

    On Tuesday, March 31, 2015 at 4:52:20 PM UTC-5, Charles Haynes wrote:

    d[0][j] is wrong. j is an index into d. you need to add another range over
    d. You're indexing into the first component of Values using the number of
    top level components, not the number of elements of that compoonent.

    http://play.golang.org/p/IkZ3uTuyCS

    -- Charles

    On Wed, Apr 1, 2015 at 8:20 AM, Caleb Spare <ces...@gmail.com
    <javascript:>> wrote:
    Can you show some of the data that you are unmarshaling?

    It would also help if you can attach a link to a runnable example on
    play.golang.org, or at least give the error you're encountering. I'm not
    sure what "Can't seem to get the 'values' out" means.

    -Caleb

    On Tue, Mar 31, 2015 at 11:41 AM, <raju....@gmail.com <javascript:>>
    wrote:
    I just started working with go and its a simple question for all of you.
    This is the struct i have and i am able to unmarshal some data that i
    have, into this. I am having trouble iterating over the struct.

    type resultSet struct {

    Results []struct {

    Series []struct {

    Columns []string `json:"columns"`

    Name string `json:"name"`

    Values [][]string `json:"values"`

    } `json:"series"`

    } `json:"results"`

    }

    for _, c := range ss.Results[0].Series {

    fmt.Println(c.Name)

    for j, d := range c.Values {

    fmt.Println(d[0][j])

    }

    }

    Can't seem to get the 'values' out. Thanks for the help.

    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send
    an email to golang-nuts...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 31, '15 at 8:46p
activeMar 31, '15 at 10:18p
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase