【问题标题】:Tsheets API update timesheet custom field c#Tsheets API更新时间表自定义字段c#
【发布时间】:2020-06-19 11:55:27
【问题描述】:

我正在尝试更新作为子项目的自定义字段。这就是我所在的位置和结果。

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;

这适用于 Postman。

   "data":
  [
    {
       "id": 45037255,
       "end": "2020-06-17T14:00:00-04:00",
       "start": "2020-06-17T12:00:00-04:00",
        "customfields": {
                    "247513": "DX Piping"
                }
    }
  ]
}

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

【问题讨论】:

  • 你能给我们所有的代码吗,我不认为问题来自你如何我们
  • 问题是自定义字段的格式。它是否正确?没有该行,其他代码可以正常工作。它是一个 JObject() 类型。我会发布更多。

标签: c# json api


【解决方案1】:

试试看

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

【讨论】:

  • 同样的结果,对不起。
  • 如果你记录你的 costCode,你有什么?
  • 还是一样的结果。
  • string costCode="DX Piping";
【解决方案2】:

添加这个就可以了:

      timesheet.customfields = new JObject();
      timesheet.customfields.Add("247513", costCode);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-23
    • 2018-07-22
    • 1970-01-01
    • 1970-01-01
    • 2017-08-25
    • 1970-01-01
    • 2015-02-20
    相关资源
    最近更新 更多