encoding-json-go

how to unmarshal json object if object is returning as empty string instead of empty struct

六月ゝ 毕业季﹏ 提交于 2021-02-05 11:37:24
问题 I'm receiving some data as JSON, but if a object is empty, it does not return a empty struct but a empty string instead, and when unmarshaling, it returns an error. So instead of data being {"key":{}} is {"key":""}} , it does not work even using omitempty field Example: https://play.golang.org/p/N1iuWBxuo1C type Store struct { Title string `json:"title,omitempty"` Item item `json:"item,omitempty"` } type item struct { Price float32 `json:"price,omitempty"` Kind string `json:"kind,omitempty"`