see the reffer issue <https://github.com/golang/go/issues/46065>
both json.RawMessage and interface{} cannot solve this problem.
```Go
// AnimalRaw can only used to delay decoding JSON
type AnimalRaw struct {
Kind string `json:"kind"`
Attr json.RawMessage `json:"attr"`
}
// Animal can only used to generate sample JSON
type Animal struct {
Kind string `json:"kind"`
Attr interface{} `json:"attr"`
}
```
在2021年5月10日星期一 UTC+8 上午3:14:45<Brian Candler> 写道:
> On Sunday, 9 May 2021 at 13:30:59 UTC+1 Ally Dale wrote:
>
>> But the way of [generate a sample JSON](
>> https://github.com/vipally/glab/blob/master/lab27/json_raw_test.go#L38)
>> in this case looks ugly:
>>
>>
> It doesn't have to be as ugly as that:
> https://play.golang.org/p/BUjUNtJP_rG
>
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/981efaec-6d5a-4b8e-b201-9db13e9b5666n%40googlegroups.com.