gpt4 book ai didi

json - 在 JSON 中转义逗号

转载 作者:IT王子 更新时间:2023-10-29 01:33:51 26 4
gpt4 key购买 nike

http://play.golang.org/p/lF2ZgAyxei

如何在 Go 中转义 JSON 标记中的逗号?

type AA struct {
MyStr string `json:"sub,ject"`
}

func main() {
jsonStr := `
{
"sub,ject": "I"
}
`
stt := new(AA)
json.Unmarshal([]byte(jsonStr), stt)
fmt.Println(stt)

t, _ := strconv.Unquote(jsonStr)
fmt.Println(t)
}

这不会获取 key ,只会返回空结果。

如何转义逗号?

最佳答案

JSON编码包解析字段标签使用的代码在tags.go中.此代码将字段名称与第一个逗号处的选项分开。无法转义逗号。

关于json - 在 JSON 中转义逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25984521/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com