[ 已解决 谢谢]go json 数据解析 出错求教
来源:SegmentFault
2023-01-09 09:54:00
0浏览
收藏
IT行业相对于一般传统行业,发展更新速度更快,一旦停止了学习,很快就会被行业所淘汰。所以我们需要踏踏实实的不断学习,精进自己的技术,尤其是初学者。今天golang学习网给大家整理了《[ 已解决 谢谢]go json 数据解析 出错求教》,聊聊JSON、go,我们一起来看看吧!
问题内容
package main
import (
"encoding/json"
"fmt"
)
type S struct {
Ss []SS
}
type SS struct {
Id int64 `json:"id,omitempty"`
Name string `json:"name"`
Index int8 `json:"index"`
Grids map[string]Num `json:"grids"`
}
type Num struct {
Id int64 `json:"id,omitempty"`
Left int8 `json:"left"`
Top int8 `json:"top"`
Zindex int8 `json:"zindex"`
Width int8 `json:"width"`
Height int8 `json:"height"`
Resource map[string]Re `json:"resource"`
}
type Re struct {
Id string `json:"id"`
Stype int8 `json:"stype"`
Url string `json:"url,omitempty"`
Fix bool `json:"fix"`
}
func main() {
d := []byte(`{
"5513d144004c81781fc06242": {
"id": "5513d144004c81781fc06242",
"name": "大会模式1",
"index": 1,
"grids": {
"5513d144004c81781fc06243": {
"id": "5513d144004c81781fc06243",
"left": 0,
"top": 0,
"zindex": 1328,
"width": 800,
"height": 0,
"resource": {
"id": "55110ecb695a0ce8209ad1d2",
"stype": 0,
"url": "",
"fix": false
}
},
"5513d144004c81781fc06244": {
"id": "5513d144004c81781fc06244",
"left": 0,
"top": 0,
"zindex": 1328,
"width": 800,
"height": 0,
"resource": {
"id": "55110f22e04aedcc20ffc71d",
"stype": 0,
"url": "",
"fix": false
}
}
}
},
"5513d14b004c81781fc06245": {
"id": "5513d14b004c81781fc06245",
"name": "大会模式2",
"index": 2,
"grids": {
"5513d14b004c81781fc06246": {
"id": "5513d14b004c81781fc06246",
"left": 0,
"top": 0,
"zindex": 1328,
"width": 800,
"height": 0,
"resource": {
"id": "55110ecb695a0ce8209ad1d2",
"stype": 0,
"url": "",
"fix": false
}
},
"5513d14b004c81781fc06247": {
"id": "5513d14b004c81781fc06247",
"left": 0,
"top": 0,
"zindex": 1328,
"width": 800,
"height": 0,
"resource": {
"id": "55110f22e04aedcc20ffc71d",
"stype": 0,
"url": "",
"fix": false
}
}
}
},
"5513d151004c81781fc06248": {
"id": "5513d151004c81781fc06248",
"name": "大会模式3",
"index": 3,
"grids": {}
},
"5513d2a6908a81e019539845": {
"id": "5513d2a6908a81e019539845",
"name": "大会模式16",
"index": 4,
"grids": {
"5513d834f8788e642cc16409": {
"id": "5513d834f8788e642cc16409",
"left": 138,
"top": 10,
"zindex": 20000,
"width": 800,
"height": 0,
"resource": {
"id": "55110f14695a0ce8209ad1d3",
"stype": 0,
"url": "",
"fix": false
}
},
"5513d834f8788e642cc1640a": {
"id": "5513d834f8788e642cc1640a",
"left": 0,
"top": 0,
"zindex": 1328,
"width": 800,
"height": 0,
"resource": {
"id": "55110f14695a0ce8209ad1d3",
"stype": 0,
"url": "",
"fix": false
}
}
}
},
"5513d3180cc83bbc17864613": {
"id": "5513d3180cc83bbc17864613",
"name": " 大会模式16",
"index": 5,
"grids": {
"5513d862f8788e642cc1640d": {
"id": "5513d862f8788e642cc1640d",
"left": 138,
"top": 10,
"zindex": 20000,
"width": 800,
"height": 0,
"resource": {
"id": "55110f14695a0ce8209ad1d3",
"stype": 0,
"url": "",
"fix": false
}
},
"5513d862f8788e642cc1640e": {
"id": "5513d862f8788e642cc1640e",
"left": 0,
"top": 0,
"zindex": 1328,
"width": 800,
"height": 0,
"resource": {
"id": "55110f14695a0ce8209ad1d3",
"stype": 0,
"url": "",
"fix": false
}
}
}
},
"5513d34cb59421b41f66accc": {
"id": "5513d34cb59421b41f66accc",
"name": "大会模式6",
"index": 6,
"grids": {
"5513d34cb59421b41f66accd": {
"id": "5513d34cb59421b41f66accd",
"left": 138,
"top": 10,
"zindex": 20000,
"width": 800,
"height": 0,
"resource": {
"id": "",
"stype": 0,
"url": "",
"fix": false
}
},
"5513d34cb59421b41f66acce": {
"id": "5513d34cb59421b41f66acce",
"left": 0,
"top": 0,
"zindex": 1328,
"width": 800,
"height": 0,
"resource": {
"id": "",
"stype": 0,
"url": "",
"fix": false
}
}
}
},
"5513dc4587b8fa481c7dfa32": {
"id": "5513dc4587b8fa481c7dfa32",
"name": "大会模式5",
"index": 7,
"grids": {
"5513dc4587b8fa481c7dfa33": {
"id": "5513dc4587b8fa481c7dfa33",
"left": 138,
"top": 100,
"zindex": 2000,
"width": 800,
"height": 10,
"resource": {
"id": "55110ecb695a0ce8209ad1d2",
"stype": 0,
"url": "",
"fix": false
}
}
}
}
}`)
var objs S
err := json.Unmarshal(d, &objs)
if err != nil {
fmt.Println("err", err)
}
fmt.Println(objs)
}
输出结果是:

我想知道哪里出错了·~ 谢谢
正确答案
用下面这段JSON 就可以了,直接给你找到了,别问我哪里出的问题,以后这种问题麻烦自己找,别来这里面问,就是一体力活,这点事情都还要找别人来做,还是别玩IT了。
里面总共有两个错误,一个是对象数据最后一项后面加了一个
,符号,另一个是少了一个
}符号,具体在哪个位置我也忘记了。
{
"5513d144004c81781fc06242": {
"id": "5513d144004c81781fc06242",
"name": "大会模式1",
"index": 1,
"grids": {
"5513d144004c81781fc06243": {
"id": "5513d144004c81781fc06243",
"left": 0,
"top": 0,
"zindex": 1328,
"width": 800,
"height": 0,
"resource": {
"id": "55110ecb695a0ce8209ad1d2",
"stype": 0,
"url": "",
"fix": false
}
},
"5513d144004c81781fc06244": {
"id": "5513d144004c81781fc06244",
"left": 0,
"top": 0,
"zindex": 1328,
"width": 800,
"height": 0,
"resource": {
"id": "55110f22e04aedcc20ffc71d",
"stype": 0,
"url": "",
"fix": false
}
}
}
},
"5513d14b004c81781fc06245": {
"id": "5513d14b004c81781fc06245",
"name": "大会模式2",
"index": 2,
"grids": {
"5513d14b004c81781fc06246": {
"id": "5513d14b004c81781fc06246",
"left": 0,
"top": 0,
"zindex": 1328,
"width": 800,
"height": 0,
"resource": {
"id": "55110ecb695a0ce8209ad1d2",
"stype": 0,
"url": "",
"fix": false
}
},
"5513d14b004c81781fc06247": {
"id": "5513d14b004c81781fc06247",
"left": 0,
"top": 0,
"zindex": 1328,
"width": 800,
"height": 0,
"resource": {
"id": "55110f22e04aedcc20ffc71d",
"stype": 0,
"url": "",
"fix": false
}
}
}
},
"5513d151004c81781fc06248": {
"id": "5513d151004c81781fc06248",
"name": "大会模式3",
"index": 3,
"grids": {}
},
"5513d2a6908a81e019539845": {
"id": "5513d2a6908a81e019539845",
"name": "大会模式16",
"index": 4,
"grids": {
"5513d834f8788e642cc16409": {
"id": "5513d834f8788e642cc16409",
"left": 138,
"top": 10,
"zindex": 20000,
"width": 800,
"height": 0,
"resource": {
"id": "55110f14695a0ce8209ad1d3",
"stype": 0,
"url": "",
"fix": false
}
},
"5513d834f8788e642cc1640a": {
"id": "5513d834f8788e642cc1640a",
"left": 0,
"top": 0,
"zindex": 1328,
"width": 800,
"height": 0,
"resource": {
"id": "55110f14695a0ce8209ad1d3",
"stype": 0,
"url": "",
"fix": false
}
}
}
},
"5513d3180cc83bbc17864613": {
"id": "5513d3180cc83bbc17864613",
"name": " 大会模式16",
"index": 5,
"grids": {
"5513d862f8788e642cc1640d": {
"id": "5513d862f8788e642cc1640d",
"left": 138,
"top": 10,
"zindex": 20000,
"width": 800,
"height": 0,
"resource": {
"id": "55110f14695a0ce8209ad1d3",
"stype": 0,
"url": "",
"fix": false
}
},
"5513d862f8788e642cc1640e": {
"id": "5513d862f8788e642cc1640e",
"left": 0,
"top": 0,
"zindex": 1328,
"width": 800,
"height": 0,
"resource": {
"id": "55110f14695a0ce8209ad1d3",
"stype": 0,
"url": "",
"fix": false
}
}
}
},
"5513d34cb59421b41f66accc": {
"id": "5513d34cb59421b41f66accc",
"name": "大会模式6",
"index": 6,
"grids": {
"5513d34cb59421b41f66accd": {
"id": "5513d34cb59421b41f66accd",
"left": 138,
"top": 10,
"zindex": 20000,
"width": 800,
"height": 0,
"resource": {
"id": "",
"stype": 0,
"url": "",
"fix": false
}
},
"5513d34cb59421b41f66acce": {
"id": "5513d34cb59421b41f66acce",
"left": 0,
"top": 0,
"zindex": 1328,
"width": 800,
"height": 0,
"resource": {
"id": "",
"stype": 0,
"url": "",
"fix": false
}
}
}
},
"5513dc4587b8fa481c7dfa32": {
"id": "5513dc4587b8fa481c7dfa32",
"name": "大会模式5",
"index": 7,
"grids": {
"5513dc4587b8fa481c7dfa33": {
"id": "5513dc4587b8fa481c7dfa33",
"left": 138,
"top": 100,
"zindex": 2000,
"width": 800,
"height": 10,
"resource": {
"id": "55110ecb695a0ce8209ad1d2",
"stype": 0,
"url": "",
"fix": false
}
}
}
}
}
好了,本文到此结束,带大家了解了《[ 已解决 谢谢]go json 数据解析 出错求教》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多Golang知识!
版本声明
本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
在使用GO向Mongodb插入数据的问题
- 上一篇
- 在使用GO向Mongodb插入数据的问题
- 下一篇
- golang中msgpack序列化array问题
评论列表
-
- 明理的故事
- 这篇技术文章真及时,太详细了,受益颇多,码起来,关注作者了!希望作者能多写Golang相关的文章。
- 2023-04-08 05:49:14
-
- 闪闪的狗
- 细节满满,码起来,感谢大佬的这篇文章内容,我会继续支持!
- 2023-03-14 16:14:29
-
- 淡淡的万宝路
- 这篇博文太及时了,博主加油!
- 2023-02-27 20:01:02
-
- 悦耳的蜡烛
- 这篇技术贴太及时了,太细致了,赞 ??,已加入收藏夹了,关注大佬了!希望大佬能多写Golang相关的文章。
- 2023-01-27 11:22:55
-
- 悦耳的小猫咪
- 写的不错,一直没懂这个问题,但其实工作中常常有遇到...不过今天到这,看完之后很有帮助,总算是懂了,感谢老哥分享技术贴!
- 2023-01-24 01:56:25
-
- 天真的柚子
- 好细啊,码起来,感谢楼主的这篇博文,我会继续支持!
- 2023-01-22 15:46:51
-
- 默默的巨人
- 这篇文章出现的刚刚好,楼主加油!
- 2023-01-18 01:38:09
-
- 健壮的中心
- 受益颇多,一直没懂这个问题,但其实工作中常常有遇到...不过今天到这,看完之后很有帮助,总算是懂了,感谢楼主分享博文!
- 2023-01-14 07:33:03
查看更多
最新文章
-
- Golang · Go问答 | 17分钟前 | 标准库 · 时间处理 · Go问答 · Go time.Parse ParseInLocation RFC3339 时区缩写 IANA 时区
- Go time.Parse 为什么带时区缩写的时间容易解析错
- 481浏览 收藏
-
- Golang · Go问答 | 19分钟前 | 标准库 · strconv · Go问答 · Go 进制转换 二进制 十六进制 Uint64 strconv.FormatUint AppendUint
- Go strconv.FormatUint 怎样按进制输出无符号整数
- 247浏览 收藏
-
- Golang · Go问答 | 24分钟前 | unicode · Go问答 · Go UTF-8 strings.TrimSpace 控制字符 unicode.IsSpace Unicode White Space 零宽字符
- Go strings.TrimSpace 为什么不会删除所有不可见字节
- 325浏览 收藏
-
- Golang · Go问答 | 26分钟前 |
- Go regexp.MatchString 为什么不能跨行匹配默认文本
- 196浏览 收藏
-
- Golang · Go问答 | 26分钟前 | 标准库 · Go问答 · Go 浮点数转换 Uint64 Accuracy math/big.Float.Uint64 math.MaxUint64
- Go math/big.Float.Uint64 超出范围时为什么返回最大值
- 230浏览 收藏
-
- Golang · Go问答 | 58分钟前 | 标准库 · xml · Go问答 · Go XML解析 encoding/xml xml.Decoder.Entity XML实体
- Go xml.Decoder.Entity 怎样自定义 XML 实体替换
- 220浏览 收藏
查看更多
课程推荐
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 543次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 516次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 500次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 485次学习
查看更多
AI推荐
-
- PubMedQA
- 深入了解PubMedQA生物医学问答数据集,涵盖其核心功能、使用方法及在临床决策、药物研发等场景的应用,助力提升NLP模型性能。
- 1102次使用
-
- H2O EvalGPT
- H2O EvalGPT是H2O.ai推出的开源LLM评估平台,提供详细的大模型性能排行榜、行业特定基准测试及A/B测试功能,助您快速选择最适合项目的高性能大语言模型。
- 1098次使用
-
- LMArena
- LMArena是加州大学伯克利分校推出的AI模型匿名评测平台。通过盲测投票机制,用户可对比不同大模型回答并生成实时排行榜,助力开发者优化模型及用户选择最佳AI工具。
- 1269次使用
-
- HELM
- 深入了解斯坦福推出的HELM(Holistic Evaluation of Language Models)大模型评测体系。本文解析其核心功能、安装配置步骤及应用场景,涵盖准确性、公平性、鲁棒性等多维度指标,助力开发者全面优化语言模型性能。
- 1210次使用
-
- MMBench
- MMBench是由上海人工智能实验室等机构联合推出的多模态基准测试平台,提供细粒度能力评估、大规模数据集及VLMEvalKit工具。本文详细介绍其核心功能、安装使用方法及应用场景,助力开发者全面评估多模态模型性能。
- 1057次使用
查看更多
相关文章
-
- 接口返回 200 但前端仍报错怎么办:从响应格式到跨域一步步排查
- 2026-06-14 332浏览
-
- Go map 并发写 panic 怎么办:从共享 map 到可控写入路径
- 2026-06-30 123浏览
-
- golang生成JSON以及解析JSON
- 2023-01-17 329浏览
-
- Go如何实现json字符串与各类struct相互转换
- 2023-01-07 377浏览
-
- Go中使用gjson来操作JSON数据的实现
- 2023-01-07 141浏览

