メソッドを持った interface を要素に持つ struct への JSON Unmarshal April 10, 2019 interface要素を持つstructへのJSON Unmarshal - すぎゃーんメモ これが参考になった。 ただ、このケースで上げているのは interface がどの struct で評価されればいいかわかっているケースだった。 例えば、これをキーに持つ JSON だった場合は struct A で、このキーがなかったら struct B で、みたいなケースは自分で JSON の中を読みにいって判別して Unmarshal する他ない。 具体例を示す。 type State struct { Modules []Module `json:"modules"` } type Module struct { Name string `json:"name
![メソッドを持った interface を要素に持つ struct への JSON Unmarshal - tellme.tokyo](https://cdn-ak-scissors.b.st-hatena.com/image/square/9f2c4eee07a704e5c03f69e3f5c97e0b983e499e/height=288;version=1;width=512/https%3A%2F%2Fraw.githubusercontent.com%2Fb4b4r07%2Ftellme.tokyo%2Fmaster%2Fstatic%2Fimages%2Fprofile.jpg)