On Wed, 12 Dec 2018, at 9:46 AM, olivier.gale...@gmail.com wrote:
> i have the same response
> [{"id":
> 62,"nom":"TEST","URI":"http://192.168.0.31/param/","IP":"192.168.0.31","MacAdress":"DE:AD:BE:EF:FE:ED","created_at":"2018-
> 12-06T20:44:57.131380+01:00","update_at":"2018-12-
> 06T21:00:40.847034+01:00","Localisation":2,"Type":1}]
>
This is what you should expect from the code you supplied. You make the GET
request and print out the response. That means you just need to parse the JSON
response.
Create a type that represents the items in your JSON response:
type Message struct {
ID string `json:"id"
Nom string `json:"nom"
// add more fields
}
Then modify your code to decode the items:
resp, err:=http.Get("http://192.168.0.28:8000/api/filter/192.168.0.31/")
if err != nil {
log.Fatalln(err)
}
defer resp.Body.Close()
var messages []Message
err := json.NewDecoder(resp.Body).Decode(&messages)
if err != nil {
log.Fatalln(err)
}
log.Printf("%s", messages)
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.