Used to write the node server API, change to static type language very uncomfortable, rules a lot ~
to be dynamic required!!!
Here are a few bags to note
JSON conversion and parsing
Github.com/bitly/go-simplejson
Go get Github.com/bitly/go-simplejson
Body conversion parsing with direct import
Stringsio/ioutil
Postman Submitting data
{"Data": "Yes", "Hotel": ["Caonima", "Gelebi"], "HP": 10000000}
Controller action data Post receive
package controllersimport ( "Github.com/revel/revel" " Io/ioutil " " strings " console " FMT " Simplejson "Github.com/bitly/go-simplejson" ) type Hotels struct { *revel. controller} type dct map[string]interface {}func (C hotels) Index () Revel. Result { if strings. Contains (c.request.contenttype, "Application/json") { content, _ := ioutil. ReadAll (c.request.body) cn_json, _ := simplejson . Newjson ([]byte (content)) console. Println (Cn_json) cn_body, _ := cn_json. Get ("Data"). String () &nbsP; cn_hotel, _ := cn_json. Get ("Hotel"). Array () cn_hp, _ := cn_json. Get ("HP"). Int () console. Println (CN_HP) console. Println (cn_body) for _, v := range cn_ Hotel { console. Println ("V", v) } } tt:=Dct{ "name": "Brother Chun", "Properties":D ct{"pet": "Grass Martini", "Skill": []string{"Domineering Spring brother Fist", "Resurrection in situ"}}, } return c.renderjson (TT)}
Golang Revel to dynamically receive JSON post data under a non-declared object