From d9b435f5e95d46fda7e4b234155144c02be4914e Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Fri, 19 Jun 2020 11:21:51 +0800 Subject: [PATCH] fix issue of chinese rune --- src/action/generator.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/action/generator.go b/src/action/generator.go index 826e80b8..d2b42d78 100644 --- a/src/action/generator.go +++ b/src/action/generator.go @@ -117,8 +117,8 @@ func Print(rows [][]string, format string, table string, colTypes []bool, fields respJson := "[]" if format == "json" || vari.HttpService { if vari.WithHead { - mapObj := RowsToMap(rows, fields) - jsonObj, _ := json.Marshal(mapObj) + mapArr := RowsToMap(rows, fields) + jsonObj, _ := json.Marshal(mapArr) respJson = string(jsonObj) } else { jsonObj, _ := json.Marshal(rows) @@ -138,13 +138,16 @@ func Print(rows [][]string, format string, table string, colTypes []bool, fields return content, respJson } -func RowsToMap(rows [][]string, fieldsToExport []string) (ret map[string]string) { - ret = map[string]string{} +func RowsToMap(rows [][]string, fieldsToExport []string) (ret []map[string]string) { + ret = []map[string]string{} for _, cols := range rows { + rowMap := map[string]string{} for j, col := range cols { - ret[fieldsToExport[j]] = col + rowMap[fieldsToExport[j]] = col } + + ret = append(ret, rowMap) } return } -- GitLab