在 golang 中,我有一個指向 struct 的二維指針切片,如下面的代碼所示。type point struct { x int y int}type cell struct { point point visited bool walls walls}type walls struct { n bool e bool s bool w bool}type maze struct { cells [][]*cell solutionStack Stack}我想將單元格切片序列化為 JSON。但是由于所有元素都是指針,調用 encode 將給出空的 JSON。序列化此切片的最佳方法是什么。我遇到的一個解決方案是創建這個 2D 切片廣告的本地副本,用實際結構替換所有指針。它會工作,但沒有
- 1 回答
- 0 關注
- 179 瀏覽
添加回答
舉報
0/150
提交
取消