2 回答

TA贡献1829条经验 获得超13个赞
如果我理解正确,这就是你想要的。
const b = `[{"id":1,"Name":"sun"}, {"id":2,"Name":"sam"}]`
persons := []*pb.Person{}
err := json.Unmarshal([]byte(b), &persons)
if err != nil {
panic(err.Error())
}
log.Println(persons)
// 2021/03/06 22:34:15 [id:1 name:"sun" id:2 name:"sam" ]

TA贡献1804条经验 获得超3个赞
不确定是否有更好的方法,但它没有封送到json结构中,而是使用编码/解码到json。ingest.stream不再抱怨了,我可以在azure-data-explorer中看到数据
//have a json struct for Group and Person to match the protbuf message posted in the question
var g Group
json.NewDecoder(&buf).Decode(&g)
var b bytes.Buffer
for i := 0; i < len(g.Persons); i++ {
e := json.NewEncoder(&b).Encode(&g.Persons[i])
if e != nil {
panic("issue marshalling protobuf")
}
}
- 2 回答
- 0 关注
- 106 浏览
添加回答
举报