带斜杠的String.Format

问题描述 投票:-3回答:1

String.Format不适用于“\”:

String.Format("{ \"aps\" : { \"alert\" : { \"title\" : \"{0}\", \"body\" : \"{1}\" } } }", "aaa", "bbb");

在此字符串中插入标题和文本的最佳方法是什么?

c# .net string.format
1个回答
1
投票

使用带有JSON的String.Format()会很痛苦。除了双引号(")字符外,您还必须担心格式占位符({)使用的大括号。即使是未转义的字符串也无法解决这个问题。

there are numerous alternatives,包括从Visual Studio中通过NuGet提供的几个选项。

© www.soinside.com 2019 - 2024. All rights reserved.