c# string.format json字符串 formatException错误

正常字符串的string.format是没问题的但是在拼接json的字符串的时候因为里面包含了 {}  花括号 里面又嵌套了 {0} {1} {2}这些要替换的关键字 所以会报错。

经过百度。

字符串中包含{或者},则需要用{{ 来代替字符 {,用}} 代替 }

  string strTemplate = "{{"C0061_Code":"{0}","C0061_Name":"{1}","C0010_SCode":"{2}","C0010_SName":"{3}","Type":"{4}"}},";//
  sb1.AppendFormat(strTemplate, row["C0061_Code"].ToString(), row["C0061_Name"].ToString(), row["C0010_SCode"].ToString(), row["C0010_SName"].ToString(),row["C0061_Type"].ToString());

原文地址:https://www.cnblogs.com/wangjunwei/p/5112784.html