[英]GoLang Unable to decode JSON object with dynamic type
我正在研究看起来像这样的结构:
"requestFieldValues": [
{
"fieldId": "string",
"label": "string",
"value": "string"
},
{
"fieldId": "string",
"label": "string",
"value": "string,
"renderedValue": {
"html": "string"
}
},
{
"fieldId": "priority",
"label": "Priority",
"value": {
"self": "string",
"iconUrl": "string",
"name": "string",
"id": "string"
}
},
{
"fieldId": "attachment",
"label": "Attachment",
"value": []
},
],
按照这种结构,我无法修复 value 属性的值。 到目前为止,我已经尝试用
type RequestFieldValues struct {
FieldId string `json:"fieldId"`
Label string `json:"label"`
Value map[string]interface{} `json:"value"`
}
和
type RequestFieldValues struct {
FieldId string `json:"fieldId"`
Label string `json:"label"`
Value string `json:"value"`
}
但我找不到任何与 Value 属性有关的工作。
使用以下结构对我有用。
type RequestFieldValues struct {
FieldId string `json:"fieldId"`
Label string `json:"label"`
Value interface{} `json:"value"`
}
type PcList struct {
Total int64 `json:"total"`
Data interface{} `json:"data"` // PCResource
}
type PcResource struct {
Id primitive.ObjectID `bson:"_id"`
DiskPercent float64 `json:"diskPercent"`
CpuPercent float64 `json:"cpuPercent"`
CreateTime int64 `json:"crateTime"`
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.