Trello C# REST-API 使用 JSON-String 更新 CustomField

问题描述

我正在用 C# (DotNet 4.8) 为我们的 trello 编写前端。 到目前为止,使用 CustomFields 创建和更新卡片是有效的。

这是我的自定义字段设置/更新方法

 public async Task SetCustomField(string card_id,string customFieldID,string text,string key,string token)
    {
        using (var httpClient = new HttpClient())
        {
            string sUrl = "https://api.trello.com/1/cards/" + card_id + "/customField/" + customFieldID + "/item?key=" + key + "&token=" + token;
            string _text = "{\"value\": {\"text\": \"" + @text + "\" }}";

            using (var request = new HttpRequestMessage(new HttpMethod("PUT"),sUrl))
            {
                request.Headers.TryAddWithoutValidation("Content - Type","application/json");
                request.Content = new StringContent(_text);
                request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

                HttpResponseMessage response = httpClient.SendAsync(request).Result;
                if (!response.IsSuccessstatusCode) 
                    MessageBox.Show("URL: " + sUrl + "\nCustomFieldID: " + customFieldID + "\nText: " + @text + "\nResponse: " + response.Content.ReadAsstringAsync().Result);
            }
        }
    } 

现在我有一个特定的 customField,需要用 JSON 字符串填充。 例如:

[{"from":"03.05.2021 00:00:00","to":"03.05.2021 00:02:00","ae":"8","rideCosts":"True","Log":"asdasdasd"},{"from":"03.05.2021 00:09:00","to":"03.05.2021 00:10:00","ae":"4"," rideCosts":"True","Log":"qweqweqwe"}]

在 trello 中,这个特定的 customField 是一个文本字段。

当我尝试更新这个特定的 customField 时,我得到一个错误:“解析正文时出错”。 我为这个特定的 customField 尝试了不同的 contentTypes,但没有成功操作字符串“text”。

有什么建议吗?

P.S.:当我直接在 trello-card 中复制/粘贴上面的示例字符串时,它工作得很好,我可以用另一种方法完美地读取和反序列化 JSON 字符串。 我只是不能把它放在那里...

附言: 我正在使用休耕的 USING 指令:

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.Json;

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)