c# - JSON字符串中的插值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);
推荐阅读
- ruby-on-rails - Rails 6 Zeitwerk 在初始化程序后卸载我的类
- google-apps-script - 用于通过 Drive.Files.insert() 函数将 excel 文件转换为电子表格的 google-apps-script 的 Google-cloud-platform API 设置
- python - python - 如何将逗号分隔的字符串转换为用引号''括起来的每个单词到python中的列表?
- c# - 如何在列表中找到最小的数字
- python - 使用 json.loads() 加载响应对象
- reactjs - 如何在 Reactjs 中使用 Jest 测试 Axios.all 和 Axios.spread
- azure - 如何在 Azure Power Shell 运行手册中访问本地文件路径
- mysql - 如何有条件地在 MySQL 中的日期之间/之前/之后选择?
- reactjs - 是否可以在不破坏布局的情况下在 ButtonGroup 内的禁用 MUI 按钮上呈现工具提示?
- jquery - Jquery按ID隐藏或显示跨度