[英]c# inserting variable in JSON string by escaping quotes
I have this JSON double quoted string and I want to insert variable idValue inside我有这个 JSON 双引号字符串,我想在里面插入变量 idValue
string json = @"
{
""Request"":
{
""ElementList"":
{
""id"": ""idValue""
}
}
}
In regular string this can be done by "+idValue+" ,but how I can do it here when I have these double quotes?在常规字符串中,这可以通过 "+idValue+" 完成,但是当我有这些双引号时,我怎么能在这里做到呢? Thanks.谢谢。
You can do this :你可以这样做 :
string json = @"
{
""Request"":
{
""ElementList"":
{
""id"": """+ idValue + @"""
}
}
}";
But personally I'd prefer to use a Json library to stringify my stuff.但我个人更喜欢使用 Json 库来字符串化我的东西。
Edit: Added missing quotation marks in the string.编辑:在字符串中添加了缺失的引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.