如何在 C# Unity 中将带有多个反逗号的长复杂文本分配给字符串?



我有下面的json作为文本,如何将此文本分配给字符串?由于其中包含多个倒逗号。隐藏每个逗号成为一项乏味的工作。我需要将文本分配给string json="";并在统一中传递播放器首选项字符串。为了以后的目的,以便我以后可以使用System.IO.File.WriteAllText(Application.persistentDataPath + "/stickers.json", json);来写入字符串

{
"android_play_store_link": "adityaspt",
"ios_app_store_link": "",
"sticker_packs": [
{
"identifier": "1",
"name": "Adi",
"publisher": "Jane Doe",
"tray_image_file": "Trayicon_Cat1.png",
"image_data_version":"1",
"avoid_cache":false,
"publisher_email":"",
"publisher_website": "",
"privacy_policy_website": "",
"license_agreement_website": "",
"stickers": [
{
"image_file": "Formidable.webp",
"emojis": ["☕","🙂"]
},
{
"image_file": "Awful.webp",
"emojis": ["😩","😰"]
},
{
"image_file": "Athletic.webp",
"emojis": ["☕","🙂"]
}
]
}
]
}

正如这里回答的那样,您可以在字符串前面使用 @ 自动转义通常会导致问题的字符。但是,出于显而易见的原因,您需要加倍报价。

例如:

string quote = @"This is an example quote where someone could say ""Hello, World!"" without having to escape using ."

这将输出(包括反斜杠(:

这是一个示例引用,有人可以说"你好,世界! 无需逃避使用 .

最新更新