Advertisement
krovn

Untitled

Oct 28th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.75 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "encoding/json"
  5.     "fmt"
  6.     "log"
  7.     "net/http"
  8. )
  9.  
  10. type lego struct {
  11.     Tagged    int `json:"width"`
  12.     Thumbnail struct {
  13.         URL   string //`json:"url"`
  14.         Title string //`json:"title"`
  15.     } //`json:"thumbnail"`
  16.     ID []int //`json:"id"`
  17. }
  18.  
  19. func main() {
  20.     http.HandleFunc("/", index)
  21.     http.ListenAndServe(":8080", nil)
  22. }
  23.  
  24. func index(w http.ResponseWriter, req *http.Request) {
  25.     var data lego
  26.     unmrshl := `{"width":300,"thumbnail":{"url":"http://facebook.com","title":"facebook"},"id":[123,120,400,12045]}`
  27.     err := json.Unmarshal([]byte(unmrshl), &data)
  28.     if err != nil {
  29.         log.Fatalln(err)
  30.     }
  31.     fmt.Fprintln(w, data.Tagged) //tagged
  32.     for i, v := range data.ID {
  33.         fmt.Fprintln(w, i, v)
  34.     }
  35.     fmt.Fprintln(w, data.Thumbnail.URL)
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement