JSON 字符串中的冒号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3121435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 17:31:16  来源:igfitidea点击:

Colon in JSON string

stringjsonescapingcolon

提问by ANNE Stahl

Can I escape a colon : that is inside a JSON string? Currently this object/value set

我可以转义冒号:它在 JSON 字符串中吗?当前此对象/值集

{ pn: "MT46H128M16LFCK-5 IT:A", 
  visible: false, 
  url: "/$ws$/29/1/products/ProductDetails.html?product=products/dram/MT46H128M16LFCK-5 IT" 
}

doesn't get read. I suspect it's due to the :Ain the pnvalue. How do I escape it or otherwise grab it?

没有被阅读。我怀疑这是由于:Apn价值。我如何逃脱或以其他方式抓住它?

回答by John Flatness

If that's your actual JSON, your problem is that the identifiers (pn, visible, url), need to be quoted ("pn", "visible", "url").

如果那是您的实际 JSON,那么您的问题是标识符(pn、visible、url)需要被引用(“pn”、“visible”、“url”)。

As the comment said, colons don't need to be escaped in JSON string literals.

正如评论所说,冒号不需要在 JSON 字符串文字中转义。