当前位置:网站首页>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))
- 待发现
边栏推荐
- electron 应用开发优秀实践
- 【报错记录】解决华擎J3455-ITX不插显示器无法开机的问题
- The common problems in laptops, continuously updated
- numpy库中的函数 bincount() where() diag() all()
- Preparation for gold three silver four: how to successfully get an Ali offer (experience + interview questions + how to prepare)
- threejs+shader 曲线点运动,飞线运动
- 为什么组合优先于继承
- 1007 Maximum Subsequence Sum (25分)
- unix环境编程 第十五章 15.10 POSIX信号量
- 信息系统项目的十大管理
猜你喜欢
随机推荐
c语言函数的递归调用(汉诺塔问题,楼梯递归问题等)
依赖注入(Dependency Injection)框架是如何实现的
15.10 the POSIX semaphore Unix environment programming chapter 15
UNIX Environment Programming Chapter 15 15.6 XSI IPC
为什么组合优先于继承
MySQL查询性能优化七种武器之索引潜水
研发需求的验收标准应该怎么写? | 敏捷实践
Unix Environment Programming Chapter 15 15.7 Message Queuing
【原创】JPA中@PrePersist和@PreUpdate的用法
unix环境编程 第十五章 15.5FIFO
Beauty Values
kubernetes中不可见的OOM
autogluon安装,使用指南,代码
Cluster understanding
关于anaconda中conda下载包或者pip下载包很慢的原因,加速下载包的方法(无视anaconda版本和环境)
1009 Product of Polynomials C语言多项式乘积(25分)
electron 应用开发优秀实践
实测办公场景下,国产远程控制软件的表现力如何?(技术解析)
How tall is the B+ tree of the MySQL index?
非科班毕业生,五面阿里:四轮技术面+HR一面已拿offer









