Home >Backend Development >Golang >How to remove '\' symbol in golang raw json input

How to remove '\' symbol in golang raw json input

王林
王林forward
2024-02-09 13:33:18809browse

How to remove \ symbol in golang raw json input

php小编小新教你如何删除golang原始json输入中的“\”符号。在处理golang原始json输入时,我们可能会遇到特殊字符“\”的问题,这会影响到数据的正确解析和使用。幸运的是,我们可以采取一些简单的步骤来删除这些“\”符号,以确保数据的准确性和可用性。下面,我将为大家详细介绍如何删除golang原始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\":\"\"
    }
]

删除原始 json 输入中的 \ 符号

请帮助谁可以修复它

解决方法

要解决此问题,您可以将 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, "\\", ""))

The above is the detailed content of How to remove '\' symbol in golang raw json input. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete