Go 数据类型struct问题
需求
如下的数据结构中,创建一个struct数据结构。
{
"event": {
"header": {
"namespace":"Alexa.Discovery",
"name":"Discover.Response",
"payloadVersion": "3",
"messageId": "<message id>"
},
"payload":{
"endpoints":[
{
"endpointId": "<unique ID of the endpoint>",
"manufacturerName": "<the manufacturer name of the endpoint>",
"modelName": "<the model name of the endpoint>",
"description": "<a description that is shown in the Alexa app>", "friendlyName": "Front door camera",
"displayCategories": [ "CAMERA" ],
"cookie": {
},
"capabilities":
[
{
"type": "AlexaInterface",
"interface": "Alexa.CameraStreamController",
"version": "3",
"cameraStreamConfigurations" : [
{
"protocols": ["RTSP"],
"resolutions": [{"width":1920, "height":1080}, {"width":1280, "height":720}],
"authorizationTypes": ["BASIC"],
"videoCodecs": ["H264", "MPEG2"],
"audioCodecs": ["G711"]
},
{
"protocols": ["RTSP"],
"resolutions": [{"width":1920, "height":1080}, {"width":1280, "height":720}],
"authorizationTypes": ["NONE"],
"videoCodecs": ["H264"],
"audioCodecs": ["AAC"]
}
]
},
{
"type": "AlexaInterface",
"interface": "Alexa.PowerController",
"version": "3"
},
{
"type": "AlexaInterface",
"interface": "Alexa.EndpointHealth",
"version": "3",
"properties": {
"supported": [
{
"name": "connectivity"
}
],
"proactivelyReported": true,
"retrievable": true
}
}
]
}
]
}
}
}
问题
capabilities 里的数据有部分是存在的,但并不是每一个都有cameraStreamConfigurations
,如何创建 capabilities
的数据结构?capabilities []Capability
?
type Endpoint struct {
capabilities []Capability `json:"capabilities"`
}
type Capability struct {
Type string `json:"type"`
Interface string `json:"interface"`
Version string `json:"version"`
Properties CapabilityProperties `json:"properties"`
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
并不一定有,就可忽略就好。omitempty