【问题标题】:How to treat %d as a string in JSON [duplicate]如何将 %d 视为 JSON 中的字符串 [重复]
【发布时间】:2020-08-02 21:33:18
【问题描述】:

我使用 Visual Code Studio 作为我的 IDE,并想编写一个简单的 sn-p 用于打印:

printf("%d", );

sn-p:

 "Print": {
    "prefix": "printf",
    "body": [
        "printf("%d",$1);",
        "$2"
    ],
    "description": "print"
}

它是一个 JSON 文件,但是它给了我一个错误 %d 并且不将 %d 视为字符串,我想。错误是:Expected commajson(514)

【问题讨论】:

  • 您在 sn-p 中需要 \" 而不是 "Take a look at this.
  • printf 的 " 弄乱了你的 json

标签: c json visual-studio-code printing code-snippets


【解决方案1】:

您需要用反斜杠转义出现在字符串中的双引号,否则看起来您正在结束并重新启动字符串:

 "Print": {
    "prefix": "printf",
    "body": [
        "printf(\"%d\",$1);",
        "$2"
    ],
    "description": "print"
}

【讨论】:

  • 谢谢!这完成了工作
猜你喜欢
  • 2014-01-19
  • 1970-01-01
  • 2019-07-22
  • 2014-06-22
  • 1970-01-01
  • 2014-07-06
  • 1970-01-01
  • 2012-02-07
相关资源
最近更新 更多