LoginSignup
9
8

More than 5 years have passed since last update.

GolangでJSONをデコードする

Last updated at Posted at 2016-04-07

APIにリクエストしてjsonを受け取ってクラスにマッピングしたい。
Golangだとjson.Unmarshalでやってくれる。

example.go
package main

import (
    "encoding/json"
    "fmt"
)

type compilationsAPI struct {
    SourceCode string
    Langid     int
}

func main() {
    var s compilationsAPI
    str := `{"sourceCode":"puts \"hello world\"","langid":1}`
    json.Unmarshal([]byte(str), &s)
    fmt.Println(s)
}

参考

9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8