Skip to content

Instantly share code, notes, and snippets.

@FilBot3
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FilBot3/591586030a9b13dd4475 to your computer and use it in GitHub Desktop.
Save FilBot3/591586030a9b13dd4475 to your computer and use it in GitHub Desktop.
GO JSON Example GET
/**
*
* http://stackoverflow.com/q/20293977/2009612
*/
package main
import (
"fmt"
"net/http"
"encoding/json"
)
func main() {
// Set the URL to get
url := "https://static.mwomercs.com/data/cw/mapdata.json"
// GET the URL, and set resp, or if an error, set err
resp, err := http.Get(url)
// Close the connection
resp.Body.Close()
// Create an Interface for the JSON Data
var mapData interface{}
// Decode, or Unmarshal the binary stream of the JSON and
// Assign to the variable of mapData
json.Unmarshal(resp, &mapData)
// Simply print the result.
fmt.Println(mapData)
}
@FilBot3
Copy link
Author

FilBot3 commented Aug 6, 2015

This results in:

json_example_get.go :26: cannot use resp (type *http.Response) as type []byte in argument to json.Unmarshal

So, I'm not sure what I'm doing wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment