Last active
August 29, 2015 14:26
-
-
Save FilBot3/591586030a9b13dd4475 to your computer and use it in GitHub Desktop.
GO JSON Example GET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* 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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This results in:
So, I'm not sure what I'm doing wrong.