当前位置:网站首页>golang 标准库json Marshal、Unmarshal坑
golang 标准库json Marshal、Unmarshal坑
2022-08-09 10:51:00 【ase2014】
坑1
int类型使用json Marshal,然后使用Unmarshal后,会转换成float64 – 向上取
demo
demo := make(map[string]interface{}, 5)
demo["a"] = 1
mv, err := json.Marshal(demo)
if err != nil {
fmt.Println("marshal failed, ", err.Error())
return
}
result := make(map[string]interface{}, 5)
err = json.Unmarshal(mv, &result)
if err != nil {
fmt.Println("unmarshal failed, ", err.Error())
return
}
fmt.Println(result["a"].(int))
输出结果
应该改为,最后一行改为float64
demo := make(map[string]interface{}, 5)
...
fmt.Println(result["a"].(float64))
- 待发现
边栏推荐
猜你喜欢

非科班毕业生,五面阿里:四轮技术面+HR一面已拿offer

2022强网杯WP

【 original 】 VMware Workstation implementation Openwrt soft routing, the ESXI, content is very detailed!

商业技术解决方案与高阶技术专题 - 数据可视化专题
![[Original] Usage of @PrePersist and @PreUpdate in JPA](/img/a0/5aebdef4a12fe55b4782b69e39b817.png)
[Original] Usage of @PrePersist and @PreUpdate in JPA

使用cpolar远程连接群晖NAS(创建临时链接)

相关系数计算,热力图绘制,代码实现

The complete grammar of CSDN's markdown editor

性能测试(05)-表达式和业务关联-json关联

ThreadLocal及其内存泄露分析
随机推荐
verbose np.matmul/np.dot/np.multiply/tf.matmul/tf.multiply/*
Solve the ali cloud oss - the original 】 【 exe double-click response can't open, to provide a solution
如何在gazebo进行 joint的转动控制
1008 Elevator (20分)
Input and output of cnn
cnn的输入输出
[Original] Usage of @PrePersist and @PreUpdate in JPA
shap库源码和代码实现
爬虫实例,获取豆瓣上某部电影的评论
Mysql多表查询
VBA实战(11) - 工作表(Sheet) 操作汇总
Error: Cannot find module ‘./application‘
unix环境编程 第十四章 14.4 I/O多路转接
2022年台湾省矢量数据(点线面)及数字高程数据下载
获取指定年度所有周的工具类
【原创】VMware Workstation实现Openwrt软路由功能,非ESXI,内容非常详细!
Unix Environment Programming Chapter 15 15.9 Shared Storage
关于anaconda中conda下载包或者pip下载包很慢的原因,加速下载包的方法(无视anaconda版本和环境)
c语言函数的递归调用(汉诺塔问题,楼梯递归问题等)
TensorFlow:NameError: name ‘input_data’ is not defined