10000 Parsing JSON data · Issue #97 · revel/revel · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Parsing JSON data #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pcrawfor opened this issue Mar 8, 2013 · 8 comments
Closed

Parsing JSON data #97

pcrawfor opened this issue Mar 8, 2013 · 8 comments

Comments

@pcrawfor
Copy link
pcrawfor commented Mar 8, 2013

Hi,

Was playing around with revel this week, one component I wanted to try was building out JSON API, responding with JSON was no prob but I haven't been able to figure out how to properly parse JSON data posted to an action.

I may be missing something but couldn't find a good way to handle it using the Binder.

@robfig
Copy link
Contributor
robfig commented Mar 8, 2013

Howdy,

Yea, I didn't make any particular support for that -- it was not very obvious what to make, and even without the support it is pretty straightforward with encoding/json:

func (c Application) Test() rev.Result {
    mentions := []struct {
        Text string `json:text`
    }{}
    err := json.NewDecoder(c.Request.Body).Decode(&mentions)
    if err != nil {
        rev.ERROR.Println(err)
    }
    rev.INFO.Println(mentions)
    return c.RenderText("ok")
}

Let me know if that doesn't work for your use case, or if you see an opportunity for improving it

Thanks!
-Rob

@pcrawfor
Copy link
Author
pcrawfor commented Mar 8, 2013

Thanks Rob, will give it a try and let you know

@pcrawfor
Copy link
Author
pcrawfor commented Mar 9, 2013

Hey Rob, that works fine I may take a stab at trying to do something a bit more automatic when requests come in with content type of application/json. Will let you know if I come up with anything.

Thanks

@tejainece
Copy link

@robfig Posted solution will not allow automatic binding, action parameters, etc.

@kumarsiva07
Copy link
kumarsiva07 commented Jun 1, 2016

@robfig @brendensoares Can you add this to params.go in master?

func (c Application) Test() rev.Result {
    mentions := []struct {
        Text string `json:text`
    }{}
    err := json.NewDecoder(c.Request.Body).Decode(&mentions)
    if err != nil {
        rev.ERROR.Println(err)
    }
    rev.INFO.Println(mentions)
    return c.RenderText("ok")
}

@jeevatkm
Copy link
Contributor
jeevatkm commented Jun 1, 2016

@kumarsiva07 Can you describe your use case?

@kumarsiva07
Copy link

Yes. I am using react instead of revel templates.
So all the request will have request data in the form of json. It's a
application/json type request.
On 2 Jun 2016 2:50 am, "Jeevanandam M." notifications@github.com wrote:

@kumarsiva07 https://github.com/kumarsiva07 Can you describe your use
case?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#97 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AHXgdqsHiz0jYrvCxovWB8ag_ow7bzu0ks5qHfcOgaJpZM4AfIxc
.

@jeevatkm
Copy link
Contributor
jeevatkm commented Jun 2, 2016

@kumarsiva07 - please create an issue with your description and also mention about #97 and #110.

kumakichi pushed a commit to kumakichi/revel that referenced this issue Nov 2, 2018
Changed listener to be a pointer receiver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
0