S
S
siyoteam2015-11-20 14:42:40
go
siyoteam, 2015-11-20 14:42:40

Golang and working with json, where is the mistake?

Hello toaster.
Do not tell me how to work with json.
There is y in my application API that returns json and it needs to be accepted by the application on go.
Rummaged through all the docks, but their examples do not work =)

type test struct {
  status string `json:"status"`
}

func getRequest(url string) {
  client := &http.Client{}
  resp, _ := client.Get(url)
  defer resp.Body.Close()
  f := new(test)
  err := json.NewDecoder(resp.Body).Decode(f);
  if (err != nil) {
    log.Println(err.Error())
  }
  fmt.Println(f.status)
}

Everything seems to be as it should be, but as a result, "f.status" is empty
. The Json itself is the answer:{"status":"error"}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SilentFl, 2015-11-20
@siyoteam

f.status - private field. Correct on f.Status and it will be ok

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question