[TOC]
encode
[]byte 特殊問(wèn)題
json marshal []byte 有兩種方式:
- 通過(guò)定義struct 定義 []byte字段侠畔,json.Marshal(), 內(nèi)部經(jīng)過(guò)base64 encoding 處理席吴。用戶不用處理
- Unmarshal時(shí),使用 map[string]interface{}矿咕,接收Unmarshal后的數(shù)據(jù)悦荒,json就會(huì)試圖轉(zhuǎn)化成string春锋,unmarshal 后得不到原來(lái)數(shù)據(jù)累贤。
測(cè)試鏈接:https://play.golang.org/p/zTTMo3kmeHQ
decode
Unmarshal 解析字段優(yōu)先級(jí),假設(shè)json字段為"Foo"
- Exported Field with Tag of "Foo"
- Exported Field named Foo
- Exported Field named "Foo", "FoO" or some other case-insensitive match of "Foo"