-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Parsing JSON data #97
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
Comments
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! |
Thanks Rob, will give it a try and let you know |
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 |
@robfig Posted solution will not allow automatic binding, action parameters, etc. |
@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")
} |
@kumarsiva07 Can you describe your use case? |
Yes. I am using react instead of revel templates.
|
@kumarsiva07 - please create an issue with your description and also mention about #97 and #110. |
Changed listener to be a pointer receiver
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.
The text was updated successfully, but these errors were encountered: