Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "encoding/json"
- "fmt"
- "log"
- "net/http"
- )
- type lego struct {
- Tagged int `json:"width"`
- Thumbnail struct {
- URL string //`json:"url"`
- Title string //`json:"title"`
- } //`json:"thumbnail"`
- ID []int //`json:"id"`
- }
- func main() {
- http.HandleFunc("/", index)
- http.ListenAndServe(":8080", nil)
- }
- func index(w http.ResponseWriter, req *http.Request) {
- var data lego
- unmrshl := `{"width":300,"thumbnail":{"url":"http://facebook.com","title":"facebook"},"id":[123,120,400,12045]}`
- err := json.Unmarshal([]byte(unmrshl), &data)
- if err != nil {
- log.Fatalln(err)
- }
- fmt.Fprintln(w, data.Tagged) //tagged
- for i, v := range data.ID {
- fmt.Fprintln(w, i, v)
- }
- fmt.Fprintln(w, data.Thumbnail.URL)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement