3 2 7

问答 / 235 / 7 / 创建于 1年前 / 更新于 1年前

> 类型1
{
  "id":1,

  "result": [{
    "topics": ["bbbbbbbb"],
    "payload": "aaaaa...",
    ...//多字段
    }]
}

类型2
{
   id:2,
  "result": ["aaaaaaaaaa"]
}

类型3
{
   id:2,
  "result": ["aaaaaaaaaa", "bbbbbbbbbbb"]
}

type Contents struct{
    Result interface{}
}

请问应该如何定义 Result 的类型来兼容这三种类型的json?

Result map[string]interface{}    // 这种类型能够处理多层嵌套的json但是无法处理 单个值的json