const string format = "\"{0}\": {\n"; string.Format(format, sample);
としたときに Format の指定が間違っているエラーが出て変換できなかった
FormatException: Input string was not in a correct format.
\"
, \'
, \n
, \\
などエスケープできるのは知っていたが {
のエスケープ方法は知らなかった
調べてみると {{
, }}
とすることで {
と }
が エスケープできることが分かった
ということで先程の format は以下のようにすると問題なく動作する
const string format = "\"{0}\": {{\n"; string.Format(format, sample);