返回为字节json,排序
This commit is contained in:
parent
46478c0679
commit
529324a55e
8
ai.go
8
ai.go
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"gitea.cdlsxd.cn/self-tools/l_ai_excel_header_match/doubao"
|
||||
|
||||
"github.com/iancoleman/orderedmap"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -31,15 +31,15 @@ func ExcelMatch(ctx context.Context, selfExcelHeader, matchToExcelHeader []strin
|
|||
}
|
||||
|
||||
func OrderMapWithSlice(data map[string]interface{}, desiredOrder []string) ([]byte, error) {
|
||||
m := orderedmap.New()
|
||||
|
||||
var orderedKVs []map[string]interface{}
|
||||
for _, key := range desiredOrder {
|
||||
if value, exists := data[key]; exists {
|
||||
orderedKVs = append(orderedKVs, map[string]interface{}{key: value})
|
||||
m.Set(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
// 编码为 JSON
|
||||
return json.MarshalIndent(orderedKVs, "", " ")
|
||||
return json.MarshalIndent(m, "", " ")
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue