簡體   English   中英

GoLang 無法解碼動態類型的 JSON 對象

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM