如何创建一组具有相同标头的多个JSON



我有一个JSON,它之前要创建以下模式达到API,见下文

    "recipientSetInfos":    
     [
          {
            "recipientSetMemberInfos":          
            [
              {
                "fax": "",
                "email": ""
              }
            ],
            "recipientSetRole":         
            {
              "SIGNER": "enum",
              "APPROVER": "enum"
            },
            "signingOrder": 0
          }
        ]

使用这个预定义的格式,我想创建多个签名者集,就像下面一样。

   "recipientSetInfos": 
    [
      {
        "recipientSetMemberInfos": 
        [{
            "email": "def@gmail.com"
        }],
        "recipientSetRole": "SIGNER"
    }, {
        "recipientSetMemberInfos": [{
            "email": "abc@gmail.com"
        }],
        "recipientSetRole": "SIGNER"
    }],

我正在使用C#编程语言,如果我只是硬编码它&邮寄它工作,但如果我想动态创建。我怎样才能做到这一点。目前我使用这个像

        RecipientSetInfo rec_Info = new RecipientSetInfo();
        rec_Info.recipientSetMemberInfos = List_Emails;
        rec_Info.recipientSetRole = "SIGNER";
        List_Recipients.Add(rec_Info);

其输出为:

          {
            "recipientSetMemberInfos":
                [
                    {"email":"abc@ae.com"},
                    {"email":"def@gmail.com"},
                    {"email":"fgh@gmail.com"}
                ],
            "recipientSetRole":"SIGNER"
           }

但是使用这个逻辑,我没有得到想要的输出。是的将所有3封电子邮件视为一封。

只是想补充一点,在一位用户的帮助下,我试图编码出这个

foreach (var email in List_Emails)
{
    var rec_Info = new RecipientSetInfo();
    rec_Info.recipientSetRole = "SIGNER";
    List_Recipients.Add(rec_Info);
}

但问题仍然存在,因为"receiventSetInfos"有两个分部,即receiventsetRole&recipientSetMemberInfos,其中"recipientSet MemberInfos"有一个属性"电子邮件"。

所以当我把这两个列表加在一起时,结果是电子邮件为空

"recipientSetInfos":
[
    {"recipientSetMemberInfos":null,
     "recipientSetRole":"SIGNER"
    ‌​},
    {"recipientSetMemberInfos":null,
     "recipientSetRole":"SIGNER"
    }
]

我创建的两个元素的结构,如-

public class RecipientSetMemberInfo
    {
        public string email { get; set; }
    }
    public class RecipientSetInfo
    {
        public List<RecipientSetMemberInfo> recipientSetMemberInfos { get; set; }
        public string recipientSetRole { get; set; }
    }

请建议??

您的问题是为每个电子邮件创建一个RecipientSetInfo,而不是

以下内容将循环通过List_Emails集合,并将它们添加到列表List_Recipients中。

foreach (var email in List_Emails)
{
    var rec_Info = new RecipientSetInfo();
    rec_Info.recipientSetRole = "SIGNER";
    List_Recipients.Add(rec_Info);
}

相关内容

  • 没有找到相关文章

最新更新