json - 如何在 golang 中打印未编码的数据?

标签 json go glide-golang

我正在 golang 中从 Raabbitmq 读取 json 并将该 json 映射到接口(interface)中

我的结构看起来像这样,并且

type Documents struct {
    user_id    string
    partner_id []string
    last_login int
}

我正在上面的结构中映射传入的json,但是出于debugginf的目的,我想查看接口(interface)数组,我如何打印映射的数据数组(在我的例子中是主体)

        var body []Documents
        json.Unmarshal(d.Body, &body)

        log.Printf("Received a message: %s", body)

我需要输入其他标识符来代替 %s 吗?

最佳答案

您的结构定义有问题。您需要使用导出的标识符,例如 -

type Documents struct {
    UserID    string    `json:"user_id"`
    PartnerID []string  `json:"partner_id"`
    LastLogin int       `json:"last_login"`
}

您的问题请引用格式printing verbs .

打印正文的值-

log.Printf("Received a message: %v", body)

打印值和变量名称 -

log.Printf("Received a message: %#v", body)

关于json - 如何在 golang 中打印未编码的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44964648/

相关文章:

jquery - JSON 响应不会附加到 div

go - 如何调用静态HTML文件

go - 如何修复这个简单程序中的 'declared but not used' 编译器错误?

docker - 在 Docker 中设置 Go Glide

go - 我们可以参数化 glide.yaml 文件吗?

php - 从mysql返回数据到html

java - 将对象插入到 jsonarray 中的特定位置

haskell - 如何从 Golang 调用 Haskell 函数?

bash - MINGW64 "make build"错误 : "bash: make: command not found"

MySQL JSON 数组用于 "IN"子句?