【发布时间】:2016-03-24 18:08:46
【问题描述】:
给定这个多行字符串:
string strProviderJSON = @"
{
""npi"":""1111111111"",
""name"":""DME Clearinghouse"",
""email"":""my@doc.como"",
""contactName"":""Sally Smith"",
""fax"":"""",
""address"":{
""country"":""United States"",
""street1"":""27787 Dequindre Apt 616"",
""street2"":"""",
""city"":""Madison Heights"",
""state"":""MI"",
""zipCode"":""32003""
},
""phone"":""(904) 739-0300"",
""contactPhone"":""(904) 739-0300""
}
";
如何在其中连接变量?我试过了,但总是报错:
string strTest = "1111111111";
string strProviderJSON = @"
{
""npi"":""" + strTest + """,
""name"":""DME Clearinghouse"",
""email"":""my@doc.como"",
""contactName"":""Sally Smith"",
""fax"":"""",
""address"":{
""country"":""United States"",
""street1"":""27787 Dequindre Apt 616"",
""street2"":"""",
""city"":""Madison Heights"",
""state"":""MI"",
""zipCode"":""32003""
},
""phone"":""(904) 739-0300"",
""contactPhone"":""(904) 739-0300""
}
";
【问题讨论】:
-
使用 JSON 库!!!那些双引号很可怕,我想不出有什么好的理由
-
@JoePhilllips 你会推荐哪个?我认为我必须从那里的整个字符串中制作一个对象,然后将其传递给 JSON 库?
-
newtonsoft json 是 c# 的常用格式。你甚至可以制作一个匿名对象并使用它。很简单,会清理你的代码很多