将字节数组设置为 json.RawMessage

set array of byts to json.RawMessage

我在 golang 中有字节数组:

obj_data, _ := json.Marshal(obj)

并且想要将这个字节数组设置为 json.RawMessage 我认为它会起作用:

data := json.RawMessage{obj_data}

但我有错误:

cannot use obj_data (type []byte) as type byte in array element

请帮帮我! =)

您需要 type conversion,而不是文字:

data := json.RawMessage(obj_data)