为了账号安全,请及时绑定邮箱和手机立即绑定

将 JSON 解组为结构

将 JSON 解组为结构

Go
至尊宝的传说 2023-02-06 18:55:22
我正在尝试将以下 JSON 字符串解组到下面的结构中;{   "io.confluent.connect.avro.ConnectDefault":{      "lastModifiedAt":{         "string":"2022-09-01T02:22:19+00:00"      },      "taxRateId":{         "int":5      },      "basedOn":{         "string":"Markup"      },      "priceTax":{         "double":2.04      },      "price":{         "int":24      },      "status":{         "string":"active"      },      "costPrice":{         "int":24      },      "createdAt":{         "string":"2022-09-01T02:22:19+00:00"      },      "productId":{         "int":3545      },      "ownershipId":{         "int":1      },      "dbId":{         "int":3655      },      "markupPercentage":{         "int":0      }   }}type Wrapper struct {    Message `json:"io.confluent.connect.avro.ConnectDefault"`}type Message struct {    DbId Field `json:"dbId"`}type Field struct {    Value map[string]interface{}}但它给了我Field地图的空值。不确定我在这里做错了什么。JSON去解组
查看完整描述

1 回答

?
萧十郎

TA贡献1815条经验 获得超12个赞

这是因为您有额外的嵌套级别:

type Message struct {
    DbId map[string]interface{} `json:"dbId"`}

dbId属性的值是map任何东西的一个string


查看完整回答
反对 回复 2023-02-06
  • 1 回答
  • 0 关注
  • 76 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信