json - golang中具有嵌套结构的json对象
问题描述
我有以下 json 对象,我试图用 Go 将其表示为 atype JsonObject struct
并将其传递回其原始 json,以便我可以将 json 作为 api 端点返回。有什么建议/例子吗?
[{
"time": 173000,
"id": "VLSuEE5m1kmIhgE7ZhHDFe",
"height": "",
"DATASTRUCTURE": {
},
"language": "en",
"size": 0,
"url": "http://www.gstatic.com/play.m3u8",
"type": "vid",
"definitionid": "h264",
"reference": "PAN-EN",
"content": "This is some content",
"revisiondate": "2017-11-29T00:00:00",
"data": {
},
"id": "BBBB3424-153E-49DE-4786-013B6611BBBB",
"thumbs": {
"32": "https://www.gstatic.com/images?q=tbn:ANd9GcRj",
"64": "https://www.gstatic.com/images?q=tbn:DPd3GcRj"
},
"title": "Cafeteria",
"hash": "BBBB5d39bea20edf76c94133be61BBBB"
}]
解决方案
您可以使用https://mholt.github.io/json-to-go/ 为给定的 json 模式生成结构。例如,问题中给出的 json 可以表示为:
type AutoGenerated []struct {
Time int `json:"time"`
ID string `json:"id"`
Height string `json:"height"`
DATASTRUCTURE struct {
} `json:"DATASTRUCTURE"`
Language string `json:"language"`
Size int `json:"size"`
URL string `json:"url"`
Type string `json:"type"`
Definitionid string `json:"definitionid"`
Reference string `json:"reference"`
Content string `json:"content"`
Revisiondate string `json:"revisiondate"`
Data struct {
} `json:"data"`
Thumbs struct {
Num32 string `json:"32"`
Num64 string `json:"64"`
} `json:"thumbs"`
Title string `json:"title"`
Hash string `json:"hash"`}
希望这可以帮助!
推荐阅读
- javascript - 加载时如何动态更改表中行的颜色
- c - 处理 I/O 的流程主管
- c# - 如何通过 wpf c# 中的条件以编程方式禁用组合框的特定项目
- react-native - 如何在“React-Native Expo”中打开闪光灯?
- mongodb - 我们可以使用 mongodb 将对象值推送到 $project 中吗
- python - 如何根据文件夹名称命名图例中的图形
- docker - Docker 中的 .NET Core,过期的 SSL CA 证书
- python - 我的 python IDE 无法运行我的文件。我该如何解决?
- java - 通过 nginx 的 Webflux 媒体流有时会失败
- youtube-api - Youtube API v3 - 管理其他人拥有的频道