go - Golang parse JSON returns 0 -



go - Golang parse JSON returns 0 -

the json @ tempting parse basic , looks this.

{"id": 3, "title":"test"}

the next code attempting utilize creating , parsing json.

package main import ( "fmt" "encoding/json" ) type config struct{ id int title string } func main() { var jsonstr = []byte(`{"id": 3, "title":"test"}`) var conf config err := json.unmarshal(jsonstr, &conf) if err!=nil{ fmt.print("error:",err) } fmt.println(conf) fmt.println(string(jsonstr)) }

been looking on lot of different code examples , can't see i'm doing wrong. when effort run this, return.

{0 } {"id": 3, "title":"test"}

i have verified json valid, go on empty homecoming when attempting utilize json.unmarshal. ideas on missing can json parsed?

edit: looks can work if capitalize titles (id, title). unfortunately homecoming testing homecoming api returns in lowercase. need able parse json lowercase titles listed above.

your config struct's fields need exported (upper-case), keys in json object may remain lower-case.

see here: http://play.golang.org/p/0a5tkckso5

json go

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -