FAQ
hi,

below is the part of my code which used to get the field name.

*var opts Obje*





*e := reflect.ValueOf(opts)e.Type().Field(i).Name*It is working fine..but
the problem is for the first struct it gives the output as

*"xmlname":{"space":"","local":"email"}*

I want to get the *"email"* only...how to do that?

--
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/groups/opt_out.

Search Discussions

  • Chris dollin at Jan 24, 2014 at 11:04 am
    On 24 January 2014 10:55, kate Fernando wrote:

    hi,
    below is the part of my code which used to get the field name.

    *var opts Obje*





    *e := reflect.ValueOf(opts)e.Type().Field(i).Name*It is working fine..but
    the problem is for the first struct it gives the output as

    *"xmlname":{"space":"","local":"email"}*

    I want to get the *"email"* only...how to do that?
    Don't output the field called "space"?

    Chris

    --
    Chris "allusive" Dollin

    --
    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/groups/opt_out.
  • kate Fernando at Jan 24, 2014 at 11:17 am
    sorry..I didn't get your question..when I use *e.Type().Field(i).Name ,*
      from *XMLName xml.Name **`xml:"email"`*

    it gives the output as above...but I need to get the output "email" only

    --
    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/groups/opt_out.
  • kate Fernando at Jan 24, 2014 at 11:46 am
    I think that you didn't get my question...this is the code which I
    implement so far to convert go object to json string

    *func reflection(opts interface{}) { *

    * e := reflect.ValueOf(opts)*

    * for i := 0; i < e.NumField(); i++ {*



    * if e.Field(i).Kind() == reflect.Struct {*


      * fmt.Printf("%q", strings.ToLower(e.Type().Field(i).Name))*


      * fmt.Print(":")*

    * fmt.Printf("{\n")*

    * reflection(e.Field(i).Interface())*

    * }*


      * if e.Field(i).Kind() == reflect.String {*


      * fmt.Printf("%q\n", strings.ToLower(e.Type().Field(i).Name))*

    * fmt.Print(":")*

    * fmt.Printf("\"%v\"", e.Field(i).Interface())*

    * fmt.Printf(",")*


      * }*





    * }*






    * }The outut is*{"xmlname":{

    "space"

    :"",

    "local"

    :"email",


    "id"

    :"203934839",

    "to":{

    "email"

    :"john@google.com",

    "text"

    :"John Boris",


    "from":{

    "email"

    :"me@google.com",

    "text"

    :"My Name",


    "subject"

    :"Reminder",

    "body"

    :"You need to get grocery before coming home!",

    }


    In here I need to omit the part

    *"xmlname":{*

    *"space"*

    *:"",*

    *"local"*

    *:"email",*


    and get the "email" only...How can I do that?


    --
    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/groups/opt_out.
  • Ian Lance Taylor at Jan 24, 2014 at 2:38 pm

    On Fri, Jan 24, 2014 at 3:46 AM, kate Fernando wrote:
    In here I need to omit the part

    "xmlname":{

    "space"

    :"",

    "local"

    :"email",


    and get the "email" only...How can I do that?
    You haven't shown us a complete code example. You haven't told us
    what is different about "space" that causes you to want to omit it.
    Whatever is different, test for that.

    Ian

    --
    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/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 24, '14 at 10:55a
activeJan 24, '14 at 2:38p
posts5
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase