Open xiaozhiliaoo opened 1 year ago
You try to marshal an umsorted map m
. The result is also unsorted which is ok.
May be you need to sort m
first before marshalling.
...
sort.Strings(keys)
sort.Strings(m)
// marshal m
// and then do the check/ print
...
the map is ordered by sort
This was a surprise to me, but you are right: the built-in encoding/json package documentation says:
"Map values encode as JSON objects... The map keys are sorted and used as JSON object keys..."
May be you need to sort m first before marshalling.
You can't sort a map in Go. Maps have no guaranteed order. The only way to do it is to copy the key-value pairs into some other data structure.
the map is ordered by sort. but jsoniter.Marshal make the map unordered. but json.Marshal json.Marshal