how to remove the " \ " sign in the input in golang raw json

huangapple go评论80阅读模式
英文:

how to remove the " \ " sign in the input in golang raw json

问题

以下是翻译好的内容:

这是一个输入示例:

[
{
"type":"非定制",
"so_no":"3250109150",
"material_code":"F100101180028",
"po_no":"JDC/00067/02/22/2/DL",
"pr_no":"",
"gr_no":"",
"gr_date":""
},
{
"type":"非定制",
"so_no":"3250109150",
"material_code":"F100101180030",
"po_no":"JDC/00067/02/22/2/DL",
"pr_no":"",
"gr_no":"",
"gr_date":""
}
]

请删除原始 JSON 输入中的 \ 符号。

请帮助能够修复它的人

英文:

and this is an example of its input

[
    {
        \"type\":\"Non Custom\",
        \"so_no\":\"3250109150\",
        \"material_code\":\"F100101180028\",
        \"po_no\":\"JDC/00067/02/22/2/DL\",
        \"pr_no\":\"\",
        \"gr_no\":\"\",
        \"gr_date\":\"\"
    },
    {
        \"type\":\"Non Custom\",
        \"so_no\":\"3250109150\",
        \"material_code\":\"F100101180030\",
        \"po_no\":\"JDC/00067/02/22/2/DL\",
        \"pr_no\":\"\",
        \"gr_no\":\"\",
        \"gr_date\":\"\"
    }
]

Remove the \ sign in raw json input

And please help who can fix it

答案1

得分: -1

为了解决这个问题,你可以将JSON转换为字符串,并替换每个反斜杠,如下所示:

json := `[
    {
        \"type\":\"Non Custom\",
        \"so_no\":\"3250109150\",
        \"material_code\":\"F100101180028\",
        \"po_no\":\"JDC/00067/02/22/2/DL\",
        \"pr_no\":\"\",
        \"gr_no\":\"\",
        \"gr_date\":\"\"
    },
    {
        \"type\":\"Non Custom\",
        \"so_no\":\"3250109150\",
        \"material_code\":\"F100101180030\",
        \"po_no\":\"JDC/00067/02/22/2/DL\",
        \"pr_no\":\"\",
        \"gr_no\":\"\",
        \"gr_date\":\"\"
    }
]`
fmt.Println(strings.ReplaceAll(json, "\\",""))

请注意,这是Go语言的代码示例,用于将JSON中的反斜杠替换为空字符串。

英文:

To solve this problem, you can pass the JSON into a string and replace every backslash like shown below:

json := `[
    {
        \"type\":\"Non Custom\",
        \"so_no\":\"3250109150\",
        \"material_code\":\"F100101180028\",
        \"po_no\":\"JDC/00067/02/22/2/DL\",
        \"pr_no\":\"\",
        \"gr_no\":\"\",
        \"gr_date\":\"\"
    },
    {
        \"type\":\"Non Custom\",
        \"so_no\":\"3250109150\",
        \"material_code\":\"F100101180030\",
        \"po_no\":\"JDC/00067/02/22/2/DL\",
        \"pr_no\":\"\",
        \"gr_no\":\"\",
        \"gr_date\":\"\"
    }
]`
fmt.Println(strings.ReplaceAll(json, "\\", ""))

huangapple
  • 本文由 发表于 2023年1月31日 17:56:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75295384.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定