- take out the key of map and put it into a slice s to sort and traverse, V: = range s, take the value: map [v] from the map and put it in the array in turn OL> 0
var err error
msgs = make([]*configModel.SysMailMsg, len(cacheMap))
keys := make([]int, len(cacheMap))
i := 0
for k, _ := range cacheMap {
if keys[i], err = strconv.Atoi(k); err != nil {
return nil, err
}
i++
}
sort.Ints(keys)
mi := 0
for _, v := range keys {
var tmp configModel.SysMailMsg
json.UnmarshalFromString(cacheMap[strconv.Itoa(v)], &tmp)
msgs[mi] = &tmp
mi++
}
Read More:
- JSON and map convert to each other (using fastjson)
- Tensorflow ValueError: Failed to convert a NumPy array to a Tensor
- NotImplementedError: Cannot convert a symbolic Tensor (LSTM/strided_slice:0) to a numpy array
- Array of PHP_ diff,array_ intersect,array_ merge, in_ Is there a limit on the number of arrays in array?
- Map to vector pair map.second sort
- [solved] error: valueerror: expected 2D array, got scalar array instead
- How to get all the keys of map by golang
- Two dimensional array and pointer to one dimensional array
- Error handling when ABP specifies map object during map operation
- [go] solve the fatal error of go: concurrent map writes map non concurrent security
- How to Install Python 3 in Centos7 Quickly
- Android 9 (P) recovery upgrade Map of ‘@/cache/recovery/block.map’ failed problem analysis guide
- Easynvr operation log reports an error. Fatal error: concurrent map read and map write troubleshooting
- Quickly create a local typescript running environment.
- Variable type error: error of array occurs when TP5 controller receives the array of post
- How to use C + + function pointer array
- Tdengine failed to start, start request repeated too quickly for taosd.service
- Error 1: Vue quickly clicks the route to jump. Error: uncaught (in promise) error: request aborted
- A solution to automatically convert special characters into Unicode when taking out data from MySQL and encapsulating it into JSON