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)