【问题标题】:Getting Newtonsoft.Json.JsonSerializationException error when deserializing a Json object反序列化 Json 对象时出现 Newtonsoft.Json.JsonSerializationException 错误
【发布时间】:2020-01-21 17:42:04
【问题描述】:

我在尝试通过其 API 服务发送带有自定义收件人邮件(使用 recipientMailNotification)的 Docusign envelope 时遇到问题。我的控制器正确接收请求,但在它发送到 docusign 服务之前,它会反序列化为一个对象,这就是错误发生的时候。

**JSON Request:**


"Recipients": [{
            "Order": 1,
            "Name": "Andre Test ",
            "Email": "andre@test.com",
            "SignerType": "SIGNER",
            "DocusignSignerType": 0,
            "SignatureType": "ELECTRONIC",
            "EtapaFinalizada": false,
            "EmailNotification":{
                "emailBody": "SIGN AS SIGNER",
                "emailSubject": "SIGNER SIGNATURE REQUIRED"
            }
        },
        {
            "Order": 2,
            "Name": "Luis Teste",
            "Email": "luis@test.com",
            "SignerType": "WITNESS",
            "DocusignSignerType": 0,
            "SignatureType": "ELECTRONIC",
            "EtapaFinalizada": false,
            "EmailNotification": {
                "emailBody": "SIGN AS WITNESS",
                "emailSubject": "WITNESS SIGNATURE REQUIRED"
            }
        }
    ]

给我错误:

'Cannot deserialize the current JSON object 
(e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[eSignature.
Providers.Docusign.Entities.RecipientEmailNotification]'

我没有使用任何类型的列表 或数组。只是嵌套在另一个内部的标准属性。

尝试了here 列出的解决方案,但仍然出现错误。

使用 Json2CSharp 给了我与我当前类相同的结构,所以我认为它是正确的 Json。

编辑:请注意,我什至没有在我的类属性上使用数组或列表:

public class Destinatario
{
    public int Order { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }
    public string SignerType{ get; set; }
    public int DocusignSignerType{ get; set; }
    public string SignatureType{ get; set; }
    public bool EtapaFinalizada { get; set; }
    public RecipientEmailNotification EmailNotification { get; set; }
}

【问题讨论】:

  • 您使用的是 DocuSign.eSign.dll nuget 包吗?如果是这样 - 什么版本?
  • @InbarGazit 没有。我只使用 eSign Rest API 2.1 版
  • 好的,所以您使用的是自己的对象,所以我真的不知道序列化失败的原因是什么。我建议你考虑使用 nuget,不会有这个问题。
  • 我已经看到一个问题 - 您需要将所有内容更改为字符串。没有 int/bool 等。都是字符串。
  • 确实在反序列化 json 时需要一个列表,因为您有一个 Recipients 数组。向我们展示您的反序列化调用,错误就在那里。否则,它应该可以工作,请参阅这个小提琴example

标签: json api json.net docusignapi serialization


【解决方案1】:

收件人 JSON 如下所示:

"recipients": {
        "signers": [{
                "email": "test1@email.com",
                "name": "Name 1",
                "recipientId": "1",
                "routingOrder": "1",
                "tabs": {
                    "signHereTabs": *[{
                        "xPosition": "100",
                        "yPosition": "100",
                        "documentId": "1",
                        "pageNumber": "1"
                    }]
                }
            },
            {
                "email": "test2@email.com",
                "name": "Name 2",
                "recipientId": "2",
                "routingOrder": "2",
                "tabs": {
                    "initialHereTabs": *[{
                        "xPosition": "100",
                        "yPosition": "200",
                        "documentId": "1",
                        "pageNumber": "1"
                    }],
                    "signHereTabs": [*{
                        "xPosition": "200",
                        "yPosition": "200",
                        "documentId": "1",
                        "pageNumber": "1"
                    }]
                }
            }
        ],
        "carbonCopies": [{
                "email": "test3@email.com",
                "name": "Name 3",
                "recipientId": "3",
                "routingOrder": "3"
            },
            {
                "email": "test*4@email.com",
                "name": "Name 4",
                "recipientId": "4",
                "routingOrder": "3"
            }
        ]
    } 

您没有将其分成不同类型的收件人,因此您的 JSON 无效。

请参阅https://developers.docusign.com/esign-rest-api/guides/features/recipients 了解更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多