【问题标题】:Json.Net Post IssueJson.Net 发布问题
【发布时间】:2017-11-01 15:16:41
【问题描述】:

我是处理 Json 文档的新手。我正在使用 Team Dynamix API 并尝试创建新资产。我正在使用 ARC(高级 REST 客户端)编写测试请求。我可以编写成功的 ARC 请求,但很难用 C# 和 Json.Net 编写实际代码。如果我序列化我的 C# 请求,它看起来与 ARC 请求相同。这是我的一些代码:

Asset newAsset = new Asset{
    //attributes of asset here
}
responseMsg = await oHttpClientX.PostAsJsonAsync(addAssetUri, newAsset);

回复是:

"The following errors were encountered:\r\n * AssetRole is required.

我在我的 ARC 请求中收到了此响应,但我在 newAsset 中添加了正确的功能来修复它。也许这个问题太具体了,但我想我会问。

如果我需要澄清任何事情,请告诉我。

【问题讨论】:

  • 我不明白。你有没有解决你的问题?你在问什么?
  • 问题不清楚,您是否设法从 C# 外部调用该 api,但是从 C# 调用它时遇到该错误?您似乎缺少该对象的某个属性,但不能确定,我们需要更多信息来提供帮助
  • @KinSlayerUY 是的。我可以从 C# 外部成功调用 API,但是当我在 C# 中对 API 进行完全相同的调用时,我遇到了同样的问题。我需要在发布正确之前进行序列化吗?这可能是问题...我尝试后会更新。
  • 等等...我绝对不应该序列化。
  • REST 客户端通常进行自己的序列化。

标签: c# json api json.net


【解决方案1】:

这就是我要找的。在查看其他 API 文档并阅读 Json.NET 文档后,我能够创建资产。它看起来像这样:

Asset asset = new Asset {
    StatusID = 1067,
    Name = "computerName",
    Attributes = new List<CustomAttribute> {
        new CustomAttribute{
            Name ="AssetRole",
            ID=12345,
            Choices = new List<CustomAttributeChoice>{
                new CustomAttributeChoice{
                    ID=71745,
                    Name="Staff"
                }
            },
            Value="71745",
            ValueText="Staff",
            ChoicesText="Staff"
        }
    }
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-19
    • 1970-01-01
    • 2010-10-11
    • 1970-01-01
    • 2012-04-02
    • 1970-01-01
    • 2013-01-10
    相关资源
    最近更新 更多