如何在 C# unity 中将带有多个引号的复杂长文本分配给 String?
How to assign long complex text with multiple inverted commas to String in 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": ["☕",""]
}
]
}
]
}
如回答here,您可以在字符串前使用@来自动转义通常会导致问题的字符。但是,出于显而易见的原因,您需要加倍报价。
例如:
string quote = @"This is an example quote where someone could say ""Hello, World!"" without having to escape using \."
将输出(包括反斜杠):
This is an example quote where someone could say "Hello, World!"
without having to escape using .
我有以下 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": ["☕",""]
}
]
}
]
}
如回答here,您可以在字符串前使用@来自动转义通常会导致问题的字符。但是,出于显而易见的原因,您需要加倍报价。
例如:
string quote = @"This is an example quote where someone could say ""Hello, World!"" without having to escape using \."
将输出(包括反斜杠):
This is an example quote where someone could say "Hello, World!" without having to escape using .