FAQ
Hi,
I am new to this language...I read the xml document and convert it to go
language..now I have the object '''var email Email''.
I have to convert this object to a json string without using encoding/json
package and using *reflect* package.

following is the way how I end up with convert the object to a json string
using reflect package

       s := reflect.ValueOf(&email).Elem()

    typeOfEmail := s.Type()

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

         f := s.Field(i)

         fmt.Printf(" %s : %v\n",

             typeOfEmail.Field(i).Name, f.Interface())

     }



the output which I got is below..

XMLName : { email}

Id : 203934839

To : {{ to} john@google.com John Boris}

From : {{ from} me@google.com My Name}

Subject : Reminder

Body : You need to get grocery before coming home!


But it is not in the standard way for json...Is there any way to correct it?

THANKYOU...

--
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

  • Svip at Jan 19, 2014 at 10:49 am

    On 19 January 2014 11:29, kate Fernando wrote:

    But it is not in the standard way for json...Is there any way to correct it?
    Why not use the encoding/json package? I am more curious why you are
    not just using 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.
  • kate Fernando at Jan 19, 2014 at 11:15 am
    It is for an assignment....
    I have to use reflect package...help me..

    thankyou

    --
    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.
  • Peter Nguyen at Jan 19, 2014 at 12:14 pm
    Well, you can take a look at the encoding/json package
    (http://golang.org/pkg/encoding/json/) which also use reflect to do its job.

    Den söndagen den 19:e januari 2014 kl. 12:15:56 UTC+1 skrev kate Fernando:


    It is for an assignment....
    I have to use reflect package...help me..

    thankyou
    --
    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 19, '14 at 10:29a
activeJan 19, '14 at 12:14p
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase