V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
i4color
V2EX  ›  Go 编程语言

[]map[string]interface{} 中[]unit8 序列化成了 base64,

  •  
  •   i4color · 2020-12-15 11:13:40 +08:00 · 1041 次点击
    这是一个创建于 1220 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我在用 xorm 做数据操作,如果数字字段,返回的类型是[]uint8
    然后 gin 在做序列化时,会被转成 base64 字符串。

    而不是我想到的数字。
    大伙有没有办法解决这个问题?
    2 条回复    2020-12-15 12:27:22 +08:00
    kiddult
        1
    kiddult  
       2020-12-15 12:13:01 +08:00
    Array and slice values encode as JSON arrays, except that []byte encodes as a base64-encoded string, and a nil slice encodes as the null JSON value.

    https://golang.org/pkg/encoding/json/#Marshal

    如果是数字的话,内存里面表示不应该是[]uint8 的,看看是不是 xorm 用法错误?笨方法是定义一个新类型,然后写 Marshaler 接口,不过我猜应该不需要这种大杀器,虽然没看过,不过没理由 xorm 不支持这么基本的功能
    i4color
        2
    i4color  
    OP
       2020-12-15 12:27:22 +08:00
    作者的确是这么回复的,就转成[]unit8

    目前我只能想到手工转一下。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1178 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 18:19 · PVG 02:19 · LAX 11:19 · JFK 14:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.