我有一些json數據,其結構類似于以下內容:{ "value1": "some value" "value2": "some other value" "value3": "another value" "value4": { "data":[ { ...more nested values here with a few more levels } ] }}如何對結構進行布局,以便“value4”的所有數據都使用 Go 作為單個字符串返回?目前我正在使用json。NewDecoder(r.Body).Decode(dataValues),其中 dataValues 是一個類似于以下內容的結構:type DataValues struct {Value1 string `json:"value1"`Value2 string `json:"value2"`Value3 string `json:"value3"`// not sure how to define Value4}提前致謝!
1 回答

飲歌長嘯
TA貢獻1951條經驗 獲得超3個贊
如何對結構進行布局,以便“value4”的所有數據都使用 Go 作為單個字符串返回?
如果需要,可以使用 中的 RawMessage“延遲”取消marshaling并捕獲要視為字符串的部分。encoding/json
這是一個簡單的解決方案。
- 1 回答
- 0 關注
- 143 瀏覽
添加回答
舉報
0/150
提交
取消