FAQ
I tried like this:

type Test struct{
Name string
Token string
}
....
j, _ := json.Marshal(Test{"user","user/001"})
req, _ := http.NewRequest("post",
"http://localhost/save?listToken=blog", bytes.NewBuffer(j))
.....

but after request body decoded,it becomes:
----------------------------------------
map[Name:user Token user/001]
----------------------------------------

It can't be saved into mongodb as json document,can anybody help me to
solve this problem?




--

Search Discussions

  • Patrick Mylund Nielsen at Sep 13, 2012 at 5:10 am
    What's the problem? You can unmarshal into a map or a struct with matching
    (either by name or via a tag, e.g. `json:"name"`) fields.
    On Thu, Sep 13, 2012 at 7:07 AM, Alex Luya wrote:

    **
    I tried like this:

    type Test struct{
    Name string
    Token string
    }
    ....
    j, _ := json.Marshal(Test{"user","user/001"})
    req, _ := http.NewRequest("post", "http://localhost/save?listToken=blog",
    bytes.NewBuffer(j))
    .....

    but after request body decoded,it becomes:
    ----------------------------------------
    map[Name:user Token user/001]
    ----------------------------------------

    It can't be saved into mongodb as json document,can anybody help me to
    solve this problem?




    --

    --
  • Clbanning at Sep 13, 2012 at 1:50 pm
    https://github.com/garyburd/go-mongo
    On Thursday, September 13, 2012 12:08:20 AM UTC-5, Alex Luya wrote:

    I tried like this:

    type Test struct{
    Name string
    Token string
    }
    ....
    j, _ := json.Marshal(Test{"user","user/001"})
    req, _ := http.NewRequest("post", "http://localhost/save?listToken=blog",
    bytes.NewBuffer(j))
    .....

    but after request body decoded,it becomes:
    ----------------------------------------
    map[Name:user Token user/001]
    ----------------------------------------

    It can't be saved into mongodb as json document,can anybody help me to
    solve this problem?



    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 13, '12 at 5:10a
activeSep 13, '12 at 1:50p
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase