c# - Tsheets API更新时间表自定义字段c#
问题描述
我正在尝试更新作为子项目的自定义字段。这就是我所在的位置和结果。
string costCode= "DX Piping";
dynamic timesheet = new JObject();
timesheet.id = tsID;
timesheet.start = isoDate;
//Need to update custom field:247513 with the value in costcode should be another jobject?
timesheet.customfields["247513"] = costCode;
timesheet.end = isoDate;
这适用于邮递员。
"data":
[
{
"id": 45037255,
"end": "2020-06-17T14:00:00-04:00",
"start": "2020-06-17T12:00:00-04:00",
"customfields": {
"247513": "DX Piping"
}
}
]
}
这会导致错误:无法对空引用执行运行时绑定。谢谢参观
解决方案
试试看
if(timesheet.customfields["247513"] != null){
timesheet.customfields["247513"] = costCode;
}
else
{
timesheet.customfields.add("247513",costCode);
}
https://www.newtonsoft.com/json/help/html/M_Newtonsoft_Json_Linq_JObject_Add.htm
推荐阅读
- html - 使用“stylePreprocessorOptions”时找不到要导入的文件或无法读取的问题
- javascript - 如何重新渲染 Web 组件的单个元素?
- c - 具有嵌套 .h 文件的项目的生成文件
- python - 断言失败) !_src.empty() 在函数'cv::cvtColor
- xml - 在 Biztalk 2016 中将文档路由到多个接收者
- python - 将 pandas 数据框转换为自定义的 json
- django - 如何验证过期日期大于 Django 模型表单中的开始日期
- python-3.x - 如何在 Robot 框架中动态设置 ROBOT_LIBRARY_SCOPE
- python - 使用 for 循环在列表中搜索用户给定的数字
- powershell - 如何从树中删除所有隐藏的 .unwanted 目录?