“顶级值之后的无效字符”\ x00“ [英] "invalid character '\x00' after top-level value"

查看:1120
本文介绍了“顶级值之后的无效字符”\ x00“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在for循环中取消编组json时出现此错误。
第一次通过循环解组很好,但在下一次迭代中,我收到了这个错误。



我是golang的新手,并且此错误消息不是明确。有人可以解释在什么情况下发生了这个错误,以及我应该如何避免它。 解决方案

谢谢你回答我的问题。

这个错误是由于不正确的json在此之前,有更多的故事,这个,



我有json.RawMessage类型的字段 detail 我有SELECT查询,我试图从表中读取json并扫描到 detail 并将其附加到结构中。

>

在for循环结束时,当我查看详细信息 JSON时,它有多次使用和不使用末端大括号的相同记录。在给了它这么多的想法之后,我想通过字节来帮助细节。



例如:而不是rows.Scan(& detail)试试这个:
rows .Scan((* [] byte)(& detail))解决了上述问题

I am getting this error while unmarshalling json in a for loop. The first time through the loop is unmarshalling fine but on the next iteration I am getting this error.

I am new to golang and this error message is not clear. Can someone please explain in what cases this error occurs and how I am supposed to avoid it.

解决方案

Thank you for answering my question.

This error came due to incorrect json before that there is little more story to this,

I have a field detail of type json.RawMessage I have SELECT query where I am trying to read json from the table and scan to detail and appending it to the struct.

After for loop ends when I look at detail JSON it got same record multiple times with and without end braces. After giving it so much thinking I figured casting detail with byte helped.

Eg: instead of just rows.Scan(&detail) try this: rows.Scan((*[]byte)(&detail)) solved the above problem

这篇关于“顶级值之后的无效字符”\ x00“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆