Related problem:
I had a problem converting the structure to JSON, sending it as a response from Golang, then, later, catch the same thing in JavaScript via Ajax.
Much time has been allocated, so post the solution here.
In Go:
// web server type Foo struct { Number int `json:"number"` Title string `json:"title"` } foo_marshalled, err := json.Marshal(Foo{Number: 1, Title: "test"}) fmt.Fprint(w, string(foo_marshalled)) // write response to ResponseWriter (w)
In JavaScript:
// web call & receive in "data", thru Ajax/ other var Foo = JSON.parse(data); console.log("number: " + Foo.number); console.log("title: " + Foo.title);
Hope this helps someone. Good luck.
Manohar Reddy Poreddy Jul 30 '15 at 15:12 2015-07-30 15:12
source share