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

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

王林
Release: 2024-02-09 13:33:18
forward
838 people have browsed it

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\":\"\"
    }
]
Copy after login

删除原始 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, "\\", ""))
Copy after login

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template