[英]Interpolation in JSON string c#
Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
Console.Write(unixTimestamp);
var currentTimeUn = unixTimestamp.ToString();
string json = "{ \"Method\": \"GetShippedOrders\",\"Params\": { \"DateMin\": 1575158400, \"DateMax\": {currentTimeUn} }}";
How do I get currentTimeUn to be passed to DateMax?如何将 currentTimeUn 传递给 DateMax?
Solution using String interpolation :使用字符串插值的解决方案:
Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
var currentTimeUn = unixTimestamp.ToString();
string json = $"{{ \"Method\": \"GetShippedOrders\",\"Params\": {{ \"DateMin\": 1575158400, \"DateMax\": {currentTimeUn} }}}}";
Console.WriteLine(json);
Is this the solution you have been looking for?这是您一直在寻找的解决方案吗?
Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
var currentTimeUn = unixTimestamp.ToString();
string json = "{ \"Method\": \"GetShippedOrders\",\"Params\": { \"DateMin\": 1575158400, \"DateMax\": {"+currentTimeUn+"} }}";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.