gob:类型未注册的接口:map [string] interface {}

阿尔特姆(Artem):

gob 无法编码 map[string]interface{}

gob: type not registered for interface: map[string]interface {}

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

package main

import (
    "bytes"
    "encoding/gob"
    "encoding/json"
    "fmt"
    "log"
)

func CloneObject(a, b interface{}) []byte {
    buff := new(bytes.Buffer)
    enc := gob.NewEncoder(buff)
    dec := gob.NewDecoder(buff)
    err := enc.Encode(a)
    if err != nil {
        log.Panic("e1: ", err)
    }
    b1 := buff.Bytes()
    err = dec.Decode(b)
    if err != nil {
        log.Panic("e2: ", err)
    }
    return b1
}

func main() {
    var a interface{}
    a = map[string]interface{}{"X": 1}
    b2, err := json.Marshal(&a)
    fmt.Println(string(b2), err)

    var b interface{}
    b1 := CloneObject(&a, &b)
    fmt.Println(string(b1))
}

可以map[string]interface{}在gob中编码吗?我可以用JSON编码

安德鲁 :

gob.Register(map[string]interface{}{})

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

解组映射到map [string] interface {}后,对ma [string] [] string的类型断言失败

外部类型问题的JSON序列化-将map [string] interface {}项转换为int

读取map [string] interface {}中的数据

dynamodbattribute.UnmarshalMap将我的变量类型转换为map [string] interface {}

在map [string] interface {}的值上键入switch到[] map [string] interface {}

如何检查声明为map [string] interface {}的变量实际上是map [string] string?

golang为类型为map [string] interface {}的对象设置新值

在go开发中过度使用map [string] interface {}?

从String到map [string] interface {} golang

无法将args(类型[] string)用作类型[] interface {}

map [string] interface {}和interface {}之间的区别

使用map [string] int作为map [interface {}] interface {}类型的参数

如何通过map [string] interface {}创建字符串映射?

如何将map [string] interface {}中的不同值转换为string类型

类型化的嵌套映射map [string] interface {}返回“类型interface {}不支持索引”

在Golang中将两种或多种[] map [string] interface {}类型合并为一种

在gRPC协议缓冲区golang中创建Map [string] interface {}类型的变量

尝试xml时出错。解组结构类型为map [string] interface {}的结构

在Golang中访问类型为map [string] interface {}的嵌套地图

将map [interface {}] interface {}转换为map [string] string

使用map [string] interface {}:

转到:强制转换类型无法将map [string] interface {}映射到map [string] string

正确使用map [string] interface {}?

无法从[[] interface {}`断言类型[[] string`

如何对go lang中的map [string] interface {}类型进行多重排序?

创建 String 到 Interface 的映射,其中接口/函数参数和返回类型不同

gob:类型未注册接口:fasthbbftv1.BroadcastMessage

如何将 map[string]interface{} 转换为 map[string]string

kubectl 返回不能将字符串解组为 map[string]interface {} 类型的 Go 值