修复生成的json数据结构错误问题

This commit is contained in:
白茶清欢 2021-09-09 10:34:46 +08:00
parent c140c7d0ec
commit e8f448836a
2 changed files with 13 additions and 1 deletions

View File

@ -199,8 +199,14 @@ func (dj *DynamicJSON) getValFormat(root *JSONode) string {
} }
if root.IsHasLastBrother { if root.IsHasLastBrother {
if root.IsString {
return key + ":\"%v\","
}
return key + ":%v," return key + ":%v,"
} }
if root.IsString {
return key + ":\"%v\""
}
return key + ":%v" return key + ":%v"
} }
@ -209,10 +215,15 @@ func (dj *DynamicJSON) getValFormat(root *JSONode) string {
return "" return ""
} }
if root.IsHasLastBrother { if root.IsHasLastBrother {
if root.IsString {
return "\"%v\","
}
return "%v," return "%v,"
} }
if root.IsString {
return "\"%v\""
}
return "%v" return "%v"
} }
// getStartSymbol 计算起始的符号 // getStartSymbol 计算起始的符号

View File

@ -29,6 +29,7 @@ func TestJSON(t *testing.T) {
tree.SetValue("good.price", "180", false) tree.SetValue("good.price", "180", false)
tree.SetValue("good.unit", "$", false) tree.SetValue("good.unit", "$", false)
tree.SetValue("slice.[0].name", "zhang", 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.[1].name", "de", false)
tree.SetValue("slice.[2].name", "man", false) tree.SetValue("slice.[2].name", "man", false)
tree.SetValue("slice.[3]", "zhangdeman", false) tree.SetValue("slice.[3]", "zhangdeman", false)