http - Unable to unmarshal JSON array in Golang -


i getting below response in url , want unmarshal it, unable so. kind of response i'd unmarshal.

[   {"title": "angels , demons", "author":"dan brown", "tags":[{"tagtitle":"demigod", "tagurl": "/angeldemon}] }   {"title": "the kite runner", "author":"khalid hosseinei", "tags":[{"tagtitle":"kite", "tagurl": "/kiterunner"}] }   {"title": "dance of dragons", "author":"rr martin", "tags":[{"tagtitle":"ironthrone", "tagurl": "/got"}] } ] 

i trying unmarshal sort of response not being able so. code trying write.

res, err := http.get(url) if err != nil {     log.withfields(log.fields{         "error": err,     }).fatal("couldn't html response") } defer res.body.close() b, err := ioutil.readall(res.body) if err != nil {     log.withfields(log.fields{         "error": err,     }).fatal("couldn't read response") }  s := string(b)  var data struct {     content []struct {         title           string   `json:"title"`         author          string   `json:"author"`         tags            map[string]string   `json:"tags"`     } }  if err := json.unmarshal([]byte(s), &data); err != nil {     log.withfields(log.fields{         "error": err,     }).error("un-marshalling not done.") }  fmt.println(data.content) 

can please me in regard? in advance.

change it

var data struct {     content []struct {         title           string   `json:"title"`         author          string   `json:"author"`         tags            map[string]string   `json:"tags"`     } } 

to this

type content struct {         title           string   `json:"title"`         author          string   `json:"author"`         tags            map[string]string   `json:"tags"`  } var data []content 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -