当前位置:网站首页>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))
- 待发现
边栏推荐
猜你喜欢
MySQL索引的B+树到底有多高?
真香!肝完Alibaba这份面试通关宝典,我成功拿下今年第15个Offer
聚类了解
2022年台湾省矢量数据(点线面)及数字高程数据下载
LM小型可编程控制器软件(基于CoDeSys)笔记二十六:plc的数据存储区(模拟量输入通道部分)
arcgis制图之天地图符号样式配置
[Error record] Solve the problem that ASRock J3455-ITX cannot be turned on without a monitor plugged in
相关系数计算,热力图绘制,代码实现
Shell script combat (2nd edition) / People's Posts and Telecommunications Press Script 2 Validate input: letters and numbers only
信息系统项目的十大管理
随机推荐
[华为云在线课程][SQL语法分类][数据操作][学习笔记]
OneNote 教程,如何在 OneNote 中搜索和查找笔记?
ThreadLocal及其内存泄露分析
性能测试(03)-JDBC Request
真香!肝完Alibaba这份面试通关宝典,我成功拿下今年第15个Offer
关于anaconda中conda下载包或者pip下载包很慢的原因,加速下载包的方法(无视anaconda版本和环境)
机器学习-逻辑回归(logistics regression)
arcgis制图之天地图符号样式配置
c语言函数的递归调用(汉诺塔问题,楼梯递归问题等)
Unix Environment Programming Chapter 15 15.7 Message Queuing
MATLAB代码实现三次样条插值
[Error record] Solve the problem that ASRock J3455-ITX cannot be turned on without a monitor plugged in
备份mongodb数据库(认证)
1003 Emergency (25分)
unix环境编程 第十五章 15.6 XSI IPC
numpy库中的函数 bincount() where() diag() all()
Quartz分布式实现
MNIST机器学习入门
【原创】JPA中@PrePersist和@PreUpdate的用法
pip common commands and changing source files