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的更多相关文章

  1. 算法(第四版)C# 习题题解——1.3

    写在前面 整个项目都托管在了 Github 上:https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp 这一节内容可能会用到的库文件有 ...

  2. PAT甲级——1025 PAT Ranking

    1025 PAT Ranking Programming Ability Test (PAT) is organized by the College of Computer Science and ...

  3. sqoop sample code

    本文使用的数据库是mysql的sample database employees. download url:https://launchpad.net/test-db/employees-db-1/ ...

  4. Linux Rootkit Sample && Rootkit Defenser Analysis

    目录 . 引言 . LRK5 Rootkit . knark Rootkit . Suckit(super user control kit) . adore-ng . WNPS . Sample R ...

  5. Android开发实例详解之IMF(Android SDK Sample—SoftKeyboard)

    本博前面的文章介绍了Android开发环境的搭建和模拟器的常用操作.本次,将以Android Sample中经典的SoftKeyboard项目为例,详细解析Android上一个小型项目的开发过程和注意 ...

  6. Memcached Java Client with sample program--reference

    In my previous post, I listed down most common telnet commands for memcached with sample execution t ...

  7. Misha and Changing Handles

    Description Misha hacked the Codeforces site. Then he decided to let all the users change their hand ...

  8. Windows环境搭建与第一个C# Sample

    Redis入门 - Windows环境搭建与第一个C# Sample   什么是Redis? Redis是一个开源.支持网络.基于内存.键值对存储数据库,使用ANSI C编写.从2013年5月开始,R ...

  9. 关于乱序(shuffle)与随机采样(sample)的一点探究

    最近一个月的时间,基本上都在加班加点的写业务,在写代码的时候,也遇到了一个有趣的问题,值得记录一下. 简单来说,需求是从一个字典(python dict)中随机选出K个满足条件的key.代码如下(py ...

随机推荐

  1. Windows命令行命令总结

    转载地址:https://www.cnblogs.com/accumulater/p/7110811.html   1. gpedit.msc-----组策略 2. sndrec32-------录音 ...

  2. 【异常】Caused by: org.apache.phoenix.coprocessor.HashJoinCacheNotFoundException:

    1 详细异常 Caused by: org.apache.phoenix.coprocessor.HashJoinCacheNotFoundException: ERROR 900 (HJ01): H ...

  3. OWASP Hakcing Lab在线漏洞环境

    OWASP Hakcing Lab在线漏洞环境   OWASP hakcing-lab 是一个提供免费的远程安全(Web)挑战和 OWASP TOP 10,OWASP WebGoat,OWASP Ha ...

  4. 适配器 1、ArrayAdapter 2.SimpleAdapter

    1.ArrayAdapter(数组适配器):用于绑定格式单一的数据.数据源:可以是集合或数组 public class MainActivity extends AppCompatActivity { ...

  5. python面向对象、类、socket网络编程

    类和对象 python3统一了类与类型的概念:类==类型:从一组对象中提取相似的部分就是类:特征与技能的结合体就叫做对象: 类的功能: 初始实例化: 属性引用: 1.数据属性: 2.函数属性: 对于一 ...

  6. 8.Canny边缘检测

    #导入工具包 from imutils import * image = imread('image/school.jpg') show(image) def edge_detection(image ...

  7. zeus部署

    1.下载zeus 阿里在github上已经不维护zeus了,在网上找到一个别人贡献的 https://github.com/michael8335/zeus2 下载下来 通过shell rz命令上传到 ...

  8. action mailbox

    Action Mailer Basics和Action Mailbox Basics:邮件系统. https://edgeguides.rubyonrails.org/action_mailbox_b ...

  9. 二叉树的相关定义及BST的实现

    一.树的一些概念 树,子树,节点,叶子(终端节点),分支节点(分终端节点): 节点的度表示该节点拥有的子树个数,树的度是树内各节点度的最大值: 子节点(孩子),父节点(双亲),兄弟节点,祖先,子孙,堂 ...

  10. mysql random 字母大小写和数字

    delimiter $$drop function if exists rand_string;create function rand_string(n int) returns varchar(2 ...