golang中将Json.Number转换为int或string

 我有一个变量数据,它是一个接口。 当我打印其类型时,将其获取为json.Number。 如何将强制类型转换为int或string

如果我尝试

noticeId := notice["noticeId"].(string)

会报错

panic: interface conversion: interface {} is json.Number, not string

解决办法:

noticeId := notice["noticeId"].(json.Number).String()

标题:golang中将Json.Number转换为int或string
作者:老白阳
文章地址:https://www.oldbaiyang.com/articles/2022/05/19/1652970896291.html
-------------------------------------------------------------------------------
老白阳的博客
老白阳的YouTub频道
老白阳的B站频道
老白阳的谷歌博客

Comments

Popular posts from this blog

什么是smart原则

Markdown 语法学习文档

【Protocol Buffer】简介和安装