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

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

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

  1. [
  2. {
  3. \"type\":\"Non Custom\",
  4. \"so_no\":\"3250109150\",
  5. \"material_code\":\"F100101180028\",
  6. \"po_no\":\"JDC/00067/02/22/2/DL\",
  7. \"pr_no\":\"\",
  8. \"gr_no\":\"\",
  9. \"gr_date\":\"\"
  10. },
  11. {
  12. \"type\":\"Non Custom\",
  13. \"so_no\":\"3250109150\",
  14. \"material_code\":\"F100101180030\",
  15. \"po_no\":\"JDC/00067/02/22/2/DL\",
  16. \"pr_no\":\"\",
  17. \"gr_no\":\"\",
  18. \"gr_date\":\"\"
  19. }
  20. ]

Remove the \ sign in raw json input

And please help who can fix it

答案1

得分: -1

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

  1. json := `[
  2. {
  3. \"type\":\"Non Custom\",
  4. \"so_no\":\"3250109150\",
  5. \"material_code\":\"F100101180028\",
  6. \"po_no\":\"JDC/00067/02/22/2/DL\",
  7. \"pr_no\":\"\",
  8. \"gr_no\":\"\",
  9. \"gr_date\":\"\"
  10. },
  11. {
  12. \"type\":\"Non Custom\",
  13. \"so_no\":\"3250109150\",
  14. \"material_code\":\"F100101180030\",
  15. \"po_no\":\"JDC/00067/02/22/2/DL\",
  16. \"pr_no\":\"\",
  17. \"gr_no\":\"\",
  18. \"gr_date\":\"\"
  19. }
  20. ]`
  21. 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:

  1. json := `[
  2. {
  3. \"type\":\"Non Custom\",
  4. \"so_no\":\"3250109150\",
  5. \"material_code\":\"F100101180028\",
  6. \"po_no\":\"JDC/00067/02/22/2/DL\",
  7. \"pr_no\":\"\",
  8. \"gr_no\":\"\",
  9. \"gr_date\":\"\"
  10. },
  11. {
  12. \"type\":\"Non Custom\",
  13. \"so_no\":\"3250109150\",
  14. \"material_code\":\"F100101180030\",
  15. \"po_no\":\"JDC/00067/02/22/2/DL\",
  16. \"pr_no\":\"\",
  17. \"gr_no\":\"\",
  18. \"gr_date\":\"\"
  19. }
  20. ]`
  21. 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:

确定