第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

go "encoding/json" : marshal json 字段

go "encoding/json" : marshal json 字段

Go
瀟湘沐 2021-10-25 20:19:05
我有一個帶有 json 字段(DisplayInfo 和 FormatInfo)的 PostgreSQL 模式。該領(lǐng)域的結(jié)構(gòu)是動態(tài)的。我只能讀取和渲染它作為字符串(渲染結(jié)構(gòu)中的字符串類型):[ {    "ID":9,  "Name":"120 №1",  "DisplayInfo":"{\"path\": \"http://path/to/img.png\"}",  "Format":{       "Code":"frame-120",     "Width":120,     "Height":60,     "FormatInfo":"[{\"name\": \"\\u0413\\u043b\\u0430\\u0432\\u043d\\u043e\\u0435 \\u0438\\u0437\\u043e\\u0431\\u0440\\u0430\\u0436\\u0435\\u043d\\u0438\\u0435\", \"field_type\": \"img\", \"key\": \"path\"}]"  },  "Weight":0.075,  "Application":8,  "Url":"//path/to/game",  "Referrer":"" }]但我希望輸出字段 DisplayInfo 作為 JSON 對象。如何 ?我的渲染代碼:func renderJSON(w http.ResponseWriter, obj models.Model) {    js, err := json.Marshal(obj)    if err != nil {        http.Error(w, err.Error(), http.StatusInternalServerError)        return    }    w.Header().Set("Content-Type", "application/json; charset=utf-8")    w.Header().Set("Access-Control-Allow-Origin", "*")    w.Write(js)}UPD 1:該字段的結(jié)構(gòu)是動態(tài)的。DisplayInfo 可能有“路徑”字段,也可能沒有。他們可能有額外的字段。UPD 2. 我想輸出 DisplayInfo 和 FormatInfo 作為 json-object(not string),作為整個 object 的一部分,像這樣:[ {    "ID":9,  "Name":"120 №1",  "DisplayInfo":{"path": "http://path/to/img.png"},  "Format":{       "Code":"frame-120",     "Width":120,     "Height":60,     "FormatInfo":[{"name": "\\u0413\\u043b\\u0430\\u0432\\u043d\\u043e\\u0435 \\u0438\\u0437\\u043e\\u0431\\u0440\\u0430\\u0436\\u0435\\u043d\\u0438\\u0435", "field_type": "img", "key": "path"}]  },  "Weight":0.075,  "Application":8,  "Url":"//path/to/game",  "Referrer":"" }]UPD 3:結(jié)構(gòu)實際結(jié)構(gòu)是:type BannerSerializer struct {    ID          int    Name        string    DisplayInfo string    Format      formatSerializer    Weight      float32    Application int    Url         string    Referrer    string}  DisplayInfo 序列化為 base64 字符串(或者像 base64,不知道)
查看完整描述

3 回答

  • 3 回答
  • 0 關(guān)注
  • 215 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號