You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have this json POSTed via Ajax in this valid format:
var payload = '{"x":1,"y":2,"z":3…}';
I assume the only way to get payload in echo (either as string or json) is via c.Bind(). I tried
type Payload struct {
S string
}
var pLoad Payload
c.Bind(&pLoad)
but that doesn't work: pLoad or pLoad.S is empty.
I can't break out each json item in the struct (x, y, z…) since it's variable. For now, I'd just like to treat {"x":1,"y":2,"z":3…} as one string which eventually goes into a DB. I don't want to do
var payload = '{"a":"{"x":1,"y":2,"z":3…}"}';
either.
How do I bind a POSTed json ({"string": "string"/number}, like '{"x":1,"y":"two","z":3…}') into a struct or variable as a single string value?
The text was updated successfully, but these errors were encountered:
I don't think you can decode a string with no key into go struct. Looking into http://stackoverflow.com/a/7487892/197473, using just a string as JSON payload is not valid. You can send your request as text/plain and read request body into a string, like below:
Thanks for the b, err := ioutil.ReadAll(c.Request().Body) tip.
That works and as I was exploring different Postgres types like bytea and json, I also used
I have this json POSTed via Ajax in this valid format:
I assume the only way to get payload in echo (either as string or json) is via c.Bind(). I tried
but that doesn't work: pLoad or pLoad.S is empty.
I can't break out each json item in the struct (x, y, z…) since it's variable. For now, I'd just like to treat {"x":1,"y":2,"z":3…} as one string which eventually goes into a DB. I don't want to do
either.
How do I bind a POSTed json ({"string": "string"/number}, like '{"x":1,"y":"two","z":3…}') into a struct or variable as a single string value?
The text was updated successfully, but these errors were encountered: