golang 多级json转map
func main() {
jsonStr := `{"isSchemaConforming":true,"schemaVersion":0,"unknown.0":[{"email_address":"test1@uber.com"},{"email_address":"test2@uber.com"}]}`
dynamic := make(map[string]interface{})
json.Unmarshal([]byte(jsonStr), &dynamic)
firstEmail := dynamic["unknown.0"].([]interface{})[0].(map[string]interface{})["email_address"]
fmt.Println(firstEmail)
}
type Email struct {
Email string `json:"email_address"`
}
type EmailsList struct {
IsSchemaConforming bool `json:"isSchemaConforming"`
SchemaVersion int `json:"schemaVersion"`
Emails []Email `json:"unknown.0"`
}
func main() {
jsonStr := `{"isSchemaConforming":true,"schemaVersion":0,"unknown.0":[{"email_address":"test1@uber.com"},{"email_address":"test2@uber.com"}]}`
emails := EmailsList{}
json.Unmarshal([]byte(jsonStr), &emails)
fmt.Printf("%+v\n", emails)
}
golang 多级json转map的更多相关文章
- Go_14:GoLang中 json、map、struct 之间的相互转化
1. golang 中 json 转 struct <1. 使用 json.Unmarshal 时,结构体的每一项必须是导出项(import field).也就是说结构体的 key 对应的首字母 ...
- GoLang中 json、map、struct 之间的相互转化
1. golang 中 json 转 struct <1. 使用 json.Unmarshal 时,结构体的每一项必须是导出项(import field).也就是说结构体的 key 对应的首字母 ...
- [转] golang中struct、json、map互相转化
一.Json和struct互换 (1)Json转struct例子: type People struct { Name string `json:"name_title"` Age ...
- Golang 处理 Json(二):解码
golang 编码 json 还比较简单,而解析 json 则非常蛋疼.不像 PHP 一句 json_decode() 就能搞定.之前项目开发中,为了兼容不同客户端的需求,请求的 content-ty ...
- Golang 处理 Json(一):编码
JSON 是一种数据格式描述语言.以 key 和 value 构成的哈系结构,类似 Javascript 中的对象,python 中的字典.通常 json 格式的 key 是字符串,其值可以是任意类型 ...
- Golang - 处理json
目录 Golang - 处理json 1. 编码json 2. 解码json Golang - 处理json 1. 编码json 使用json.Marshal()函数可以对一组数据进行JSON格式的编 ...
- Golang的json包
encoding/json encoding/json是官方提供的标准json, 实现RFC 7159中定义的JSON编码和解码.使用的时候需要预定义struct,原理是通过reflection和in ...
- Golang解析json的几种方法
Golang解析json的几种方法 概要 使用Golang调用其它平台API接口时总会被多层的json串给恶心到,我记录一下自己解析json的几种方法. 一.自带的json包 func JsonUnm ...
- GO语言中json与map的转换
直接上代码(需要引入encoding/json包) // 当前程序的包名 package main // 导入其它的包 import ( "encoding/json" " ...
随机推荐
- Zabbix Server安装指南
监控模板网站 在https://share.zabbix.com/,提供了各种各样的监控模板,可以自行搜索,套用.
- 【经典dp】hdu4622Reincarnation
呕 卡64M内存卡了好久 题目描述 题目大意 给出一个字符串 S,每次询问一个区间的本质不同的子串个数.$|S| \le 2000$. 题目分析 首先无脑$n^2$个set开起来:MLE 稍微想想这 ...
- BZOJ 2219 数论之神 (CRT推论+BSGS+原根指标)
看了Po神的题解一下子就懂了A了! 不过Po神的代码出锅了-solve中"d-temp"并没有什么用QwQQwQQwQ-应该把模数除以p^temp次方才行. 来自BZOJ讨论板的h ...
- 逻辑卷----LVM的基础和应用
逻辑卷管理器 Logical Volume Manager-------逻辑卷宗管理器.逻辑扇区管理器.逻辑磁盘管理器,是Linux核心所提供的逻辑卷管理(Logical volume managem ...
- 获取BGR颜色的HSV值
import cv2import numpy as np green = np.uint8([[[152, 245, 255]]]) # 输入待转换颜色的BGR值hsv_green = cv2.cvt ...
- IDEA运行有问题debug正常解决方案
朋友们!有没有遇到这样的问题,IDEA运行有问题,debug确是正常的,不经怀疑人生! 不要慌!点击maven,clean一下,再compile一下,就好啦! 不要慌!点击maven,clean一下, ...
- yii框架学习(安装)
安装yii: 在本地安装前, 要确保PHP配置了环境变量, 通过cmd输入PHP -v 即可检测. 能看到PHP版本号, 则OK. PHP不是内部命令,则需要添加PHP环境变量. 使用compos ...
- SSM跨域配置
1.后台跨域要引用两个jar包(cors-filter-1.7.jar.java-property-utils-1.9.jar) 提供下载地址: 链接: https://pan.baidu.com/s ...
- 文件操作(stat函数)
stat函数可以获取文件信息 /*** stat.c ***/ #include<stdio.h> #include<string.h> #include<sys/sta ...
- 创建虚拟机,安装操作系统,xshell6远程链接
一.创建虚拟机 1. 首先安装vmware,注意在安装中,下面的两项不要勾选,一路下一步 2.完成安装打开之后,创建新的虚拟机 3.虚拟机创建完成,需要改配置 4.然后设置网段 5.查看服务,在运行状 ...