package main

import (
"fmt"
"encoding/json"
) type ItemMessage struct {
ItemType int `json:"itemType"`
ItemId int `json:"itemId"`
ItemCount int `json:"itemCount"`
GoodsStatue *GoodsStatue
} type GoodsStatue struct{
GoodsId int
GoodsPrice int
} func main() {
JsonString := make(map[int]string)
item := make(map[int]*GoodsStatue)
JsonString[0] = `{"itemType": 1, "itemId": 2, "itemCount": 3, "GoodsStatue":{"GoodsId": 123, "GoodsPrice": 22}}`
JsonString[1] = `{"itemType": 4, "itemId": 5, "itemCount": 6, "GoodsStatue":{"GoodsId": 456, "GoodsPrice": 33}}`
for k, v := range JsonString{
var res ItemMessage
json.Unmarshal([]byte(v), &res)
item[k] = res.GoodsStatue
}
for k, v := range item{
fmt.Printf("k= %+v, v=%+v\n", k, *v)
}
}
package main

import (
"fmt"
"encoding/json"
) type ItemMessage struct {
ItemType int `json:"itemType"`
ItemId int `json:"itemId"`
ItemCount int `json:"itemCount"`
GoodsStatue *GoodsStatue
} type GoodsStatue struct{
GoodsId int
GoodsPrice int
} func main() {
var item ItemMessage
xsk := `{"itemType": 1, "itemId": 2, "itemCount": 3, "GoodsStatue":{"GoodsId": 123, "GoodsPrice": 22}}`
json.Unmarshal([]byte(xsk), &item)
fmt.Printf("item= %+v item.GoodsStatue=%+v\n", item, *item.GoodsStatue)
}
package main

import (
"fmt"
"encoding/json"
) type ItemMessage struct {
ItemType int `json:"itemType"`
ItemId int `json:"itemId"`
ItemCount int `json:"itemCount"`
GoodsStatue *GoodsStatue
} type GoodsStatue struct{
GoodsId int
GoodsPrice int
} func main() {
item := make(map[int][]ItemMessage, 10)
JsonString := make(map[int]string)
JsonString[0] = `{"itemType": 1, "itemId": 2, "itemCount": 3, "GoodsStatue":{"GoodsId": 123, "GoodsPrice": 22}}`
JsonString[1] = `{"itemType": 4, "itemId": 5, "itemCount": 6, "GoodsStatue":{"GoodsId": 456, "GoodsPrice": 33}}`
for k, v := range JsonString{
var res ItemMessage
json.Unmarshal([]byte(v), &res)
item[k] = append(item[k], res)
}
for k,v := range item{
fmt.Printf("item=%+v item.GoodsStatue=%+v\n", item[k], *v[0].GoodsStatue)
}
}

golang json解析到map中的更多相关文章

  1. go语言之进阶篇json解析到map

    1.json解析到map(通过类型断言,找到值和value类型) 示例: package main import ( "encoding/json" "fmt" ...

  2. [GO]json解析到map

    package main import ( "encoding/json" "fmt" ) var str string func main() { m := ...

  3. Golang ---json解析

    golang官方为我们提供了标准的json解析库–encoding/json,大部分情况下,使用它已经够用了.不过这个解析包有个很大的问题–性能.它不够快,如果我们开发高性能.高并发的网络服务就无法满 ...

  4. golang timeoutHandler解析及kubernetes中的变种

    Golang里的http request timeout比较简单,但是稍不留心就容易出现错误,最近在kubernetes生产环境中出现了的一个问题让我有机会好好捋一捋golang中关于timeout中 ...

  5. json解析转map

    HashMap<String, Object> map = new HashMap<String, Object>();    JSONObject jsonObject = ...

  6. golang 标准库 sync.Map 中 nil 和 expunge 区别

    本文不是 sync.Map 源码详细解读,而是聚焦 entry 的不同状态,特别是 nil 状态和 expunge 状态的区分. entry 是 sync.Map 存放值的结构体,其值有三种,分别为 ...

  7. TypeReference -- 让Jackson Json在List/Map中识别自己的Object

    private Map<String, Object> buildHeaders(Object params) { ObjectMapper objectMapper = JacksonH ...

  8. go语言怎么从(json后的)多层map中取值

    // 一个PHP中的多层关联数组,即Go中的多层map,如何从json字符串中解析,然后取到map中的某个具体的值. // 数据结构如下: cityInfo := "{ "stat ...

  9. iOS 中json解析数据出现中文乱码的问题

    一般服务器的编码格式都是UTF8,这样通过json解析下来的的数据,一般中文是不会出现乱码,但是如果服务器的编码格式不是UTF8,通过json解析的数据中的中文容易出现luan乱码,怎么解决这个问题呢 ...

随机推荐

  1. VS下字符串与数组互相装换

    1.分割字符串IdStr为int数组Ids int[] Ids = Array.ConvertAll<string, int>(IdStr.Trim().Split(','), deleg ...

  2. CF620E New Year Tree 线段树+dfs序+bitset

    线段树维护 dfs 序是显然的. 暴力建 60 个线段树太慢,于是用 bitset 优化就好了 ~ code: #include <bits/stdc++.h> #define M 63 ...

  3. mount/umount

    mount 挂载文件系统 6的 查看当前挂载情况 7的 将文件系统挂载到目录下,这个目录中的文件随着文件系统走,文件系统挂到那,里面的文件就在哪 挂载到其他地方 指定卷标的 指定文件UUID 指定ac ...

  4. leetcode解题报告(16):Move Zeroes

    描述 Given an array nums, write a function to move all 0's to the end of it while maintaining the rela ...

  5. 如何将web转化成应用程序?

    nativefier  最近无意中发现这个开源项目,Nativefier,看着它的项目介绍,以及1w+ 的 Star,感觉自己错过了一个世纪. 介绍 Nativefier是一个命令行工具,可以轻松地为 ...

  6. 【模板】杜教筛(Sum)

    传送门 Description 给定一个正整数\(N(N\le2^{31}-1)\) 求 \[ans1=\sum_{i=1}^n \varphi(i)\] \[ans_2=\sum_{i=1}^n \ ...

  7. 20191214数组之四:数字不相同的完全平方数(关于数位上数字判断与sprintf)

    sprintf用法参见之前的随笔;(以解决):

  8. Android填坑—Error:Execution failed for task ':app:transformClassesWithDexForRelease'

    昨晚正在干着自己的事,另外一个同学说项目打包不了,但是可以debug运行.又急着需要打包apk发给那边人去测试.真的是搞事情,赶紧打开项目试试打包.项目从之前的$Eclipse$中转过来的,清楚的记得 ...

  9. 咏南中间件和开发框架全面支持DELPHI10.3.2

    咏南中间件和开发框架全面支持DELPHI10.3.2 易博龙公司2019年7月12日发布了RAD STUDIO10.3.2正式版本. 咏南中间件自2019年7月14日始,中间件.CS框架.WEB框架. ...

  10. python3.6+pycharm+robotframework 环境搭建

    参考文档:https://www.cnblogs.com/chenyuebai/p/8359577.html, https://www.cnblogs.com/jiyanjiao-702521/p/9 ...