簡體   English   中英

JSON 字符串中的插值 c#

[英]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} }}";

如何將 currentTimeUn 傳遞給 DateMax?

使用字符串插值的解決方案

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);

這是您一直在尋找的解決方案嗎?

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM