func deepCopyJSON(src map[string]interface{}, dest map[string]interface{}) error {
if src == nil {
return errors.New("src is nil. You cannot read from a nil map")
}
if dest == nil {
return errors.New("dest is nil. You cannot insert to a nil map")
}
jsonStr, err := json.Marshal(src)
if err != nil {
return err
}
err = json.Unmarshal(jsonStr, &dest)
if err != nil {
return err
}
return nil
}

  

------------------------

How to copy a map to another map?

To copy a map content need to execute a for loop and fetch the index value 1 by 1 with element and assign it to another map. Below is a short example.
 
package main
 
import (
"fmt"
)
func main() {  
    map1 := map[string]int{
        "x":1,
        "y":2,
    }
    map2 := map[string]int{}       
     
    /* Copy Content from Map1 to Map2*/
    for index,element := range map1{       
         map2[index] = element
    }
     
    for index,element := range map2{
        fmt.Println(index,"=>",element) 
    }
}
C:\golang\codes>go run example.go
x => 1
y => 2

C:\golang\codes>

go deep copy map的更多相关文章

  1. [Algo] 132. Deep Copy Undirected Graph

    Make a deep copy of an undirected graph, there could be cycles in the original graph. Assumptions Th ...

  2. [Algo] 131. Deep Copy Linked List With Random Pointer

    Each of the nodes in the linked list has another pointer pointing to a random node in the list or nu ...

  3. C# Bitmap deep copy

    今天在研究一个关于 Bitmap deep copy 的问题, 经过一系列的查询,在StackOverFlow上面找到了答案,遂记录下来: public static Bitmap DeepCopyB ...

  4. shallow copy 和 deep copy 的示例

    本文属原创,转载请注明出处:http://www.cnblogs.com/robinjava77/p/5481874.html   (Robin) Student package base; impo ...

  5. python deep copy and shallow copy

    Python中对于对象的赋值都是引用,而不是拷贝对象(Assignment statements in Python do not copy objects, they create bindings ...

  6. Deep Copy cv::StereoBM 深度拷贝

    在使用OpenCV的三维立体重建的库时,一个重要的步骤就是生成左右视图的差异图Disparity,而控制生成disparity的参数的类是cv::StereoBM,我们有时候需要拷贝一份cv::Ste ...

  7. shallow copy & deep copy

    1.深复制与浅复制的概念 ->浅复制(shallow copy)概念   在SDK Guides中(搜索copy),官方给出的浅复制概念为: Copying compound objects, ...

  8. 【C#】Deep copy of objects

    If you learned C++ carefully, you must have known something about the copy of object. For example, I ...

  9. NumPy学习(索引和切片,合并,分割,copy与deep copy)

    NumPy学习(索引和切片,合并,分割,copy与deep copy) 目录 索引和切片 合并 分割 copy与deep copy 索引和切片 通过索引和切片可以访问以及修改数组元素的值 一维数组 程 ...

随机推荐

  1. opencv-windows安装教程

    一.下载opencv 下载链接: https://opencv.org/releases/ 二.运行exe 运行exe(其实是解压),将压缩包解压到相应目录,如: D:\Program Files ( ...

  2. linux环境上报异常java.lang.NoSuchMethodError

    23-Apr-2019 18:11:35.545 INFO [http-nio-10052-exec-10] org.apache.catalina.core.ApplicationContext.l ...

  3. Ribbon【负载均衡策略】

    ribbon有7种负载均衡策略可供选择: 策略类 命名 描述 RandomRule 随机策略 随机选择server RoundRobinRule 轮询策略 按照顺序选择server(ribbon默认策 ...

  4. Centos6.5镜像下载

    CentOS6.5系统安装 1.首先打开网易开源镜像站: http://mirrors.163.com/ 当然,大家也可以使用阿里开源镜像站:http://mirrors.aliyun.com/ 2. ...

  5. django_视图相关

    使用通用视图(返回静态页面) from django.conf.urls.defaults import * from django.views.generic.simple import direc ...

  6. Nginx关联php安装及启动

    Nginx 1.10.2 php 5.6.30 [root@nginx local]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (C ...

  7. Scratch—点亮生日蜡烛

    过生日是小朋友们创作Scratch作品经常会用到的素材,今天介绍使用一些基础技能来点亮生日蜡烛的实现方法. 1.角色设计只有三种:生日蛋糕.未点燃的蜡烛.已点燃的蜡烛. 2.未点燃的蜡烛:在程序启动时 ...

  8. SAS学习笔记23 线性回归、多元回归

    线性回归 由样本资料计算的回归系数b和其他统计量一样,存在抽样误差,因此,需要对线性回归方程进行假设检验 1.方差分析 2.t检验 相关系数的假设检验 相关系数(correlation coeffic ...

  9. 项目遇到的问题:页面c:forEach循环的数据进行计算传回后台并保持到数据库

    应该还有更简单的方法 但是我不晓得 手动给文本框输入数据保存到数据库 A表 :通过订单编号 查询数据获得 B表 :通过A表中的字段查询遍历获得 问题: 手动输入文本框内容 保存到数据库 页面form提 ...

  10. java类的访问修饰符

    1.java中外部类的访问修饰符有如下四种: public,默认,abstract,final // public,默认,abstract,final. public class Test1 {} c ...