From e8f448836a14d0024229c39df4ec97c74f4e3a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 9 Sep 2021 10:34:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=9F=E6=88=90=E7=9A=84js?= =?UTF-8?q?on=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- json/build.go | 13 ++++++++++++- json/json_test.go | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/json/build.go b/json/build.go index c6cdeba..3002cd0 100644 --- a/json/build.go +++ b/json/build.go @@ -199,8 +199,14 @@ func (dj *DynamicJSON) getValFormat(root *JSONode) string { } if root.IsHasLastBrother { + if root.IsString { + return key + ":\"%v\"," + } return key + ":%v," } + if root.IsString { + return key + ":\"%v\"" + } return key + ":%v" } @@ -209,10 +215,15 @@ func (dj *DynamicJSON) getValFormat(root *JSONode) string { return "" } if root.IsHasLastBrother { + if root.IsString { + return "\"%v\"," + } return "%v," } + if root.IsString { + return "\"%v\"" + } return "%v" - } // getStartSymbol 计算起始的符号 diff --git a/json/json_test.go b/json/json_test.go index c38590c..3649588 100644 --- a/json/json_test.go +++ b/json/json_test.go @@ -29,6 +29,7 @@ func TestJSON(t *testing.T) { tree.SetValue("good.price", "180", false) tree.SetValue("good.unit", "$", false) tree.SetValue("slice.[0].name", "zhang", false) + tree.SetValue("slice.[0].age", 30, false) tree.SetValue("slice.[1].name", "de", false) tree.SetValue("slice.[2].name", "man", false) tree.SetValue("slice.[3]", "zhangdeman", false)