如何使用 JSON body 在 REST API POST 方法中传递多个记录

How to pass multiple records in REST API POST method using JSON body

我有一个要求,我需要使用 REST API POST 方法在我的自定义对象中创建多个记录。 现在的问题是我一次只能创建一条记录,但我无法在一次 REST API 调用中创建多条记录。我在网上发现通过传递 JSON 请求正文我将能够创建多个记录。 我对集成完全陌生,不了解如何在一个 REST API 调用中创建多个记录以及如何在我的 REST API.[=14= 中传递 JSON 请求正文]

有人可以帮我实现我的要求吗? 我在这里发布我的代码以供参考:

@HttpPost
    global static ID createAddress(String Address, String City, String FirstName, String LastName, String Phone, String Email
                                       ) {
        //First find the contact id matching the email.
        String ContactId = [SELECT Id
                              FROM Contact
                              WHERE Email = :Email].Id;
        //Second post the new ListofAddresses to the owner of the email.                                 
        Address__c thisAddress = new Address__c(
            Contact__c=ContactId,
            Address__c=Address,
            City__c=City,
            First_Name__c=FirstName,
            Last_Name__c=LastName,
            Phone__c=Phone,

        ); 
              /* List<Address__c> result = [SELECT Address__c, City__c, First_Name__c, Last_Name__c, Phone__c
                                   FROM Address__c
                                WHERE Contact__c = :ContactId];                          
           if(result.size() > 0){
            return null;
             }else{*/
          insert thisAddress;
          return thisAddress.Id;

             }

尝试使用此代码使用 Json 格式传递多条记录

@RestResource(urlMapping='/帐号/*') 全局 class MyRestResource {

    @HttpPost
    webService static String doPost() {
        Account account = new Account();
        RestRequest req = RestContext.request;
        List<jsonWrap> jsonWrapList = (List<jsonWrap>)JSON.deserialize(req.requestbody.tostring(),List<jsonWrap>.class);
        return 'Account Success';
    }

    public class jsonWrap{
        String Namex;
        String phonex;
        String websitex;
    }
}

样本Json

[ { "Namex": "test1", "phonex": "12312", "websitex": "test.com" }, { "Namex": "test2", "phonex": "12312", "websitex": "test.com" }, { "Namex": "test2", "phonex": "12312", "websitex": "test.com" } ]