go解析空接口

2022-07-17  本文已影响0人  小王同学123321
type Resa struct{
   Treeid map[string]interface{}
   Value string
}

       for key,value := range (*resa).Treeid{
           fmt.Println(key,value)
           ret := reflect.TypeOf(value)
           switch ret.Kind() {
           case reflect.String:
               ws.WriteString(fmt.Sprintf("%s,%s\n",key,value))
           case reflect.Slice:
               slicetreeid ,_:= json.Marshal(value)
               a:=strings.Trim(strings.Trim(string(slicetreeid),"["),"]")
               b:=strings.ReplaceAll(a,"\"","")
               ws.WriteString(fmt.Sprintf("%s,%s\n",key,b))
           }
       }
上一篇下一篇

猜你喜欢

热点阅读