sup*_*mus 5 c# variables json escaping
我有这个 JSON 双引号字符串,我想在其中插入变量 idValue
string json = @"
{
""Request"":
{
""ElementList"":
{
""id"": ""idValue""
}
}
}
Run Code Online (Sandbox Code Playgroud)
在常规字符串中,这可以通过 "+idValue+" 来完成,但是当我有这些双引号时,我如何在这里做到这一点?谢谢。
你可以这样做 :
string json = @"
{
""Request"":
{
""ElementList"":
{
""id"": """+ idValue + @"""
}
}
}";
Run Code Online (Sandbox Code Playgroud)
但就我个人而言,我更喜欢使用 Json 库来字符串化我的东西。
编辑:在字符串中添加了缺少的引号。