fix: big number lose precision via view as JSON format #52

This commit is contained in:
tiny-craft 2023-10-11 15:48:29 +08:00
parent a4412d21d4
commit 76734989d5
1 changed files with 3 additions and 6 deletions

View File

@ -175,14 +175,11 @@ func autoToType(str string) (value, resultType string) {
}
func decodeJson(str string) (string, bool) {
var data any
if (strings.HasPrefix(str, "{") && strings.HasSuffix(str, "}")) ||
(strings.HasPrefix(str, "[") && strings.HasSuffix(str, "]")) {
if err := json.Unmarshal([]byte(str), &data); err == nil {
var jsonByte []byte
if jsonByte, err = json.MarshalIndent(data, "", " "); err == nil {
return string(jsonByte), true
}
var out bytes.Buffer
if err := json.Indent(&out, []byte(str), "", " "); err == nil {
return out.String(), true
}
}
return str, false