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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

golang json 返回 不需要輸出的 struct 字段

golang json 返回 不需要輸出的 struct 字段

達(dá)令說(shuō) 2018-08-18 11:28:09
type Goods struct {     IDAutoModel     CategoryIDModel // 商品分類(lèi)     NameModel     DescriptionModel      // 商品特色描述     Stores        uint64         `json:"stores"`             // 庫(kù)存數(shù)     MinScore      uint64         `json:"min_score"`          // 積分     Weight        float64        `json:"weight"`             // 重量     TimeAllModel     Category GoodsCategory `json:"category,omitempty"` }在 返回 Goods json 列表的時(shí)候 不想輸出 Category struct。 如何 刪除 struct 里面的 struct返回 json 公用 一個(gè) struct 有的接口返回 不需要 Category 沒(méi)有關(guān)聯(lián)查,所以是空的 struct有些地方是 需要輸出 Category 的, 比如商品詳情頁(yè), 商品列表頁(yè) 就不需要輸出 商品關(guān)聯(lián)的 Categoryomitempty 和 - 根本不行
查看完整描述

1 回答

?
犯罪嫌疑人X

TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊

Struct values encode as JSON objects. Each exported struct field becomes a member of the object unless

  • the field's tag is "-", or

  • the field is empty and its tag specifies the "omitempty" option.

The empty values are false, 0, any nil pointer or interface value, and any array, slice, map, or string of length zero. The object's default key string is the struct field name but can be specified in the struct field's tag value. The "json" key in the struct field's tag value is the key name, followed by an optional comma and options. Examples:

// Field is ignored by this package.
Field int json:"-"

// Field appears in JSON as key "myName".
Field int json:"myName"

// Field appears in JSON as key "myName" and
// the field is omitted from the object if its value is empty,
// as defined above.
Field int json:"myName,omitempty"

// Field appears in JSON as key "Field" (the default), but
// the field is skipped if empty.
// Note the leading comma.
Field int json:",omitempty"
The "string" option signals that a field is stored as JSON inside a JSON-encoded string. It applies only to fields of string, floating point, integer, or boolean types. This extra level of encoding is sometimes used when communicating with JavaScript programs:

Int64String int64 json:",string"
The key name will be used if it's a non-empty string consisting of only Unicode letters, digits, dollar signs, percent signs, hyphens, underscores and slashes.

GO官方Json包


查看完整回答
反對(duì) 回復(fù) 2018-08-19
  • 1 回答
  • 0 關(guān)注
  • 2689 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

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

公眾號(hào)

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