当前位置:网站首页>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))
- 待发现
边栏推荐
- 依赖注入(Dependency Injection)框架是如何实现的
- 性能测试(01)-jmeter元件-线程组、调试取样器
- margin出bug---margin失效
- 人物 | 从程序员到架构师,我是如何快速成长的?
- Unix System Programming Chapter 15 15.2 Pipes
- electron 应用开发优秀实践
- 【 original 】 VMware Workstation implementation Openwrt soft routing, the ESXI, content is very detailed!
- unix环境编程 第十五章 15.3 函数popen和pclose
- 15.10 the POSIX semaphore Unix environment programming chapter 15
- MNIST机器学习入门
猜你喜欢

备战金三银四:如何成功拿到阿里offer(经历+面试题+如何准备)

为什么组合优先于继承

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

prometheus接入mysqld_exporter

2022年台湾省矢量数据(点线面)及数字高程数据下载

Shell script combat (2nd edition) / People's Posts and Telecommunications Press Script 1 Find programs in the PATH

华为VRRP+MSTP联动接口检测实验案例

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

1009 Product of Polynomials C语言多项式乘积(25分)

支付宝小程序的接入
随机推荐
torch.stack()的官方解释,详解以及例子
Netscope: Online visualization tool for neural network structures
unix环境编程 第十五章 15.6 XSI IPC
numpy的ndarray取数操作
pip常见命令和更改源文件
遇到恶意退款不用怕,App 内购买项目的退款通知现已可用
日期工具类
Beauty Values
UNIX Environment Programming Chapter 15 15.5FIFO
Cpolar内网穿透的面板功能介绍
numpy库中的函数 bincount() where() diag() all()
从位图到布隆过滤器
Pyhton实战汇总篇
Unix Environment Programming Chapter 15 15.3 Functions popen and pclose
C语言统计不同单词数
PoseNet: A Convolutional Network for Real-Time 6-DOF Camera Relocalization论文阅读
性能测试(03)-JDBC Request
2022强网杯WP
Tensorflow realize parameter adjustment of linear equations
jvm-类加载系统