Hey there, I got a json response from an API which my service integrates, I need only 1 data from all stuff from this json, searching on Google I found the solution below, e.g;
This code;
// replace this by fetching actual response body
responseBody := `{"textfield":"I'm a text.","num":1234,"list":[1,2,3]}`
var data map[string]interface{}
err := json.Unmarshal([]byte(responseBody), &data)
if err != nil {
panic(err)
}
fmt.Println(data["list"])
fmt.Println(data["textfield"])
Reads the following json;
{"textfield":"I'm a text.","num":1234,"list":[1,2,3]}
In my situation I have the following json structure;
{"status":"sucesso","coderro":0,"erro":"","dados":[{"idboleto":"38106","datavencimento":"2017-11-10","datapagamento":"0000-00-00","codigodebarras":"...........................","urlfatura":".............","urlboleto":"THIS IS THE ONLY DATA THAT I NEED","dataemissao":"2017-09-12","valor":"70.00","valorpago":"0.00","meucodigo":"","cpfcnpj":"xxx.xxx.xxx-xx","nome":"...............................................","email":"","celular":"","fixo":"","status":"0"}]}
I need to get the “urlboleto” value, this data is inside an array, but the filter that I use always return only one array item, the structure is always the same as shown here.
How could I implement that code above to read this first item in “dados” array and the “urlboleto” attribute?
Tnx.