json - 解码 $oid 和 $date json/bson 去

标签 json go bson

我正在尝试在 go 中解码以下 json 字符串:

{"dt": {"$date": 1422019966844}, "_id": {"$oid": "54c24d7eabb7c06d4f000371"}}

我尝试了多种不同的方法来对此进行解码,但找不到有效的方法。将其解码为对象的惯用方法是什么?

谢谢, Z.

最佳答案

如果您知道所获取的 JSON 的格式,那么最好的办法就是设计一个具有相同格式的结构。

type MyJSON struct {
    Dt struct {
        Date int64 `json:"$date"`
    } `json:"dt"`
    Id struct {
        Oid string `json:"$oid"`
    } `json:"_id"`
}

http://play.golang.org/p/C2Bc7kf0B8

关于json - 解码 $oid 和 $date json/bson 去,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28119490/

相关文章:

c# - 在 .NET 2.0 中序列化为 JSON

android - moshi 中用于转换为 json 的替代名称支持

python - 从 Python 接收 C++ 中的字符串

go - 有没有办法将 golang net/http 应用程序公开到我的本地网络?

swift - 如何在 Swift 中生成 Mongo DB ObjectID?

json - 如何使用 jq 合并多个文件中的 JSON 记录

go - 为什么没有类型不匹配错误?

javascript - 在 mongodb 中链接文档的语法

node.js - "offset"的值超出范围。它必须 >= 0 && <= 17825792

go - goroutines 垃圾是否与其 channel 一起收集?