1 回答

TA貢獻1936條經驗 獲得超7個贊
您可以使用此函數刪除不需要的數組。
func removearr(x interface{}) interface{} {
switch val := x.(type) {
case map[string]interface{}:
for k, v := range val {
val[k] = removearr(v)
}
return val
case []interface{}:
if len(val) == 1 {
// remove array only if the value is not an object
if _, ok := val[0].(map[string]interface{}); !ok {
return removearr(val[0])
}
}
for i, v := range val {
val[i] = removearr(v)
}
return val
default:
return x
}
}
https://play.golang.com/p/mwo7Y2rJ_lc
- 1 回答
- 0 關注
- 121 瀏覽
添加回答
舉報