This sample is for changing from “float64” to “int” for values did unmarshal using map[string]interface{}. When it did unmarshal using map[string]interface{}, a number with “int” was changed to “floa
This sample is for changing from “float64” to “int” for values did unmarshal using map[string]interface{}.
When it did unmarshal using map[string]interface{}, a number with “int” was changed to “float64”. And it shows an error as follows.
Error :
panic: interface conversion: interface {} is float64, not int
Sample Script : It solves using following script.
package main import (
"encoding/json"
"fmt"
"reflect"
) func main() {
data := `{"key": 10}`
var i map[string]interface{}
json.Unmarshal([]byte(data), &i) val1 := i["key"]
fmt.Printf("%v, %v\n", val1, reflect.TypeOf(val1)) // 10, float64 i["key"] = int(i["key"].(float64))
val2 := i["key"]
fmt.Printf("%v, %v\n", val2, reflect.TypeOf(val2)) // 10, int
This sample is for changing from “float64” to “int” for values did unmarshal using map[string]interface{}. When it did unmarshal using map[string]interface{}, a number with “int” was changed to “floa的更多相关文章
- 算法(第四版)C# 习题题解——1.3
写在前面 整个项目都托管在了 Github 上:https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp 这一节内容可能会用到的库文件有 ...
- PAT甲级——1025 PAT Ranking
1025 PAT Ranking Programming Ability Test (PAT) is organized by the College of Computer Science and ...
- sqoop sample code
本文使用的数据库是mysql的sample database employees. download url:https://launchpad.net/test-db/employees-db-1/ ...
- Linux Rootkit Sample && Rootkit Defenser Analysis
目录 . 引言 . LRK5 Rootkit . knark Rootkit . Suckit(super user control kit) . adore-ng . WNPS . Sample R ...
- Android开发实例详解之IMF(Android SDK Sample—SoftKeyboard)
本博前面的文章介绍了Android开发环境的搭建和模拟器的常用操作.本次,将以Android Sample中经典的SoftKeyboard项目为例,详细解析Android上一个小型项目的开发过程和注意 ...
- Memcached Java Client with sample program--reference
In my previous post, I listed down most common telnet commands for memcached with sample execution t ...
- Misha and Changing Handles
Description Misha hacked the Codeforces site. Then he decided to let all the users change their hand ...
- Windows环境搭建与第一个C# Sample
Redis入门 - Windows环境搭建与第一个C# Sample 什么是Redis? Redis是一个开源.支持网络.基于内存.键值对存储数据库,使用ANSI C编写.从2013年5月开始,R ...
- 关于乱序(shuffle)与随机采样(sample)的一点探究
最近一个月的时间,基本上都在加班加点的写业务,在写代码的时候,也遇到了一个有趣的问题,值得记录一下. 简单来说,需求是从一个字典(python dict)中随机选出K个满足条件的key.代码如下(py ...
随机推荐
- HTML之盒子变形动画
4个圆形球作圆周运动 代码: <div class="box"> <div class="box1"></div> < ...
- BootStrape基础使用
官网:www.bootcss.com 一. 全局css样式 栅格系统 栅格系统用于通过一系列的行(row)与列(column)的组合来创建页面布局 <!DOCTYPE html> < ...
- C# 中使用反射的优缺点
本文摘至于:http://blog.csdn.net/springfileld/article/details/17720537 ----------------------------------- ...
- GNU编译器:Codesourcery
Codesourcery G++是个商业软件, 不过它有个lite版本,是完全免费的,只不过没有IDE,只有commmand line. Codesourcery G++支持coldfire, pow ...
- MySQL查询多行重复数据SQL
1 详见如下 SELECT day_time,`city_code`,count(1) as num FROM t_user_register_analyse GROUP BY `day_time`, ...
- 十四,K8s集群网络flannel及canal策略
目录 k8s网络CNI之flannel k8s网络通信模型 常见CNI插件(Container,Network,Interface) 插件通信一般的解决方案 网络插件的应用 Flannel插件 fla ...
- 在values中添加colors.xml
如何在values中添加colors.xml文件?按钮上的文字,背景色的动态变化的xml放在res/drawable里,现在我就说静态的xml文件吧. res/values/colors.xml< ...
- “美登杯”上海市高校大学生程序设计赛B. 小花梨的三角形(模拟,实现)
题目链接:https://acm.ecnu.edu.cn/contest/173/problem/B/#report9 Problem B B . 小 花梨 的 三角形 时间限制:1000ms 空间限 ...
- 查看ocx控件CLSID的方法(转载)
CLSID就是classID类的标识码 1.打开注册表,window + r ,输入regedit,确定 2.点击 编辑 选择查找 3.ok拉 参考:https://blog.csdn.net/u01 ...
- 多线程(四)wait()、notify()以及notifyAll()
六.线程的等待和唤醒 1.wait()和notify()的简单示范 public class Wait extends Thread{ public synchronized void run() { ...