工作笔记02——int切片转换为string类型/GO实现MAP的排序
作者:互联网
- interface{}转换为int64
value.(int64)
- int切片转换为string类型,通过json编码
jL,err := json.Marshal(playerList)
if err != nil{
tlog.Error(err)
}
jsonList := string(jL)
- GO实现MAP的排序(转化为Struct)
func rankByWordCount(wordFrequencies map[int64]int64) pairList {
pl := make(pairList, len(wordFrequencies))
i := 0
for k, v := range wordFrequencies {
pl[i] = pair{k, v}
i++
}
sort.Sort(sort.Reverse(pl))
return pl
}
type pair struct {
Key int64
Value int64
}
type pairList []pair
func (p pairList) Len() int { return len(p) }
func (p pairList) Less(i, j int) bool { return p[i].Value < p[j].Value }
func (p pairList) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
标签:02,MAP,string,int,pairList,int64,func,pair,pl 来源: https://www.cnblogs.com/Gumi-o/p/15036569.html