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 关注
- 137 浏览
添加回答
举报