首页 > 解决方案 > 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"
                }
    }
  ]
}

这会导致错误:无法对空引用执行运行时绑定。谢谢参观

标签: c#jsonapi

解决方案


试试看

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


推荐阅读