我有代码
var body = @"{
""sender_batch_header"": {
""email_subject"": ""You have a payment"",
""sender_batch_id"": ""batch-1564759643870""
},
""items"": [
{
""recipient_type"": ""PHONE"",
""amount"": {
""value"": ""1.00"",
""currency"": ""USD""
},
""receiver"": ""4087811638"",
""note"": ""Payouts sample transaction"",
""sender_item_id"": ""item-1-1564759643870""
},
{
""recipient_type"": ""EMAIL"",
""amount"": {
""value"": ""1.00"",
""currency"": ""USD""
},
""receiver"": ""<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f38380de819690b383928a83929fdd909c9e" rel="noreferrer noopener nofollow">[email protected]</a>"",
""note"": ""Payouts sample transaction"",
""sender_item_id"": ""item-2-1564759643870""
},
{
""recipient_type"": ""PAYPAL_ID"",
""amount"": {
""value"": ""1.00"",
""currency"": ""USD""
},
""receiver"": ""FSMRBANCV8PSG"",
""note"": ""Payouts sample transaction"",
""sender_item_id"": ""item-3-1564759643871""
}
]
}";
我希望收件人的电子邮件是一个字符串/变量,所以我需要转义双引号,但是我在网上尝试过的任何方法都不起作用。这可能吗? 此代码取自https://www.paypal.com/apex/product-profile/payouts/createPayouts
我不能使用\来转义它,因为我有修饰符 @,并且它用双引号引起来,所以我不能用更多引号来转义它。
我想让 EMAIL 成为一个可以更改的变量,而不是字符串文本的一部分。
最佳答案
只需在需要创建变量的部分打破@string
即可。然后添加变量后,再次使用 @string
var emailVar = ""; //email input
var body = @"{
""sender_batch_header"": {
""email_subject"": ""You have a payment"",
""sender_batch_id"": ""batch-1564759643870""
},
""items"": [
{
""recipient_type"": ""PHONE"",
""amount"": {
""value"": ""1.00"",
""currency"": ""USD""
},
""receiver"": ""4087811638"",
""note"": ""Payouts sample transaction"",
""sender_item_id"": ""item-1-1564759643870""
},
{
""recipient_type"": " + "\"" + emailVar + "\"" + @",
""amount"": {
""value"": ""1.00"",
""currency"": ""USD""
},
""receiver"": ""<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5727247a2532341727362e27363b7934383a" rel="noreferrer noopener nofollow">[email protected]</a>"",
""note"": ""Payouts sample transaction"",
""sender_item_id"": ""item-2-1564759643870""
},
{
""recipient_type"": ""PAYPAL_ID"",
""amount"": {
""value"": ""1.00"",
""currency"": ""USD""
},
""receiver"": ""FSMRBANCV8PSG"",
""note"": ""Payouts sample transaction"",
""sender_item_id"": ""item-3-1564759643871""
}
]
}";
关于c# - 如何转义多行字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57330308/