在 C# 代码中反序列化序列化程序时出错

Error at serializer Deserialize in C# code

我正在尝试从 API 加载数据,其中包含 C# 中的 JSON 数据。但是当我尝试 serializer.Deserialize[]> 数据时出现错误。

下面是一条记录的示例API数据

   "_index": "reportingp",
   "_type": "_doc",
   "_id": "9484478",
   "_version": 1,
   "_seq_no": 493807,
   "_primary_term": 1,
   "found": true,
   "_source": {
       "claimNumber": "1234567890",
       "claimICN": "999999",
       "claimStatus": "A",
       "claimType": "I",
       "claimFirstDateService": "2022-01-08",
       "claimLastDateService": "2022-01-08",
       "isBehaviourHealth": "false",
       "claimPatientAccountNumber": "885214L",
       "claimBillingAmount": "18281.52",
       "claimPaidAmount": "872.47",
       "claimCAE": "UHONE",
       "subscriberId": "100937717",
       "memberId": "100937717",
       "subscriberFirstName": "KARIMA",
       "subscriberLastName": "AQATRANI",
       "subscriberDateOfBirth": "1962-05-02",
       "subscriberAddress": "2807 MERRILL ST ",
       "patientFirstName": "KARIMA",
       "patientLastName": "AQATRANI",
       "patientMiddleName": "S",
       "patientDateOfBirth": "1962-05-02",
       "govProgramCode": "1",
       "coverageStartDate": "2017-03-01",
       "coverageEndDate": "9999-12-31",
       "groupNumber": "NEA6",
       "relationshipCode": "EE",
       "sourceId": "lkio789456",
       "billingMpin": "002629478",
       "billingProviderName": "Mercy Gilbert Medical Center",
       "renderingMpin": "002629478",
       "ticketNumber": "9484478",
       "tpsmCode": "S",
       "ticketTpsmIndicator": "418",
       "ticketTpsmDescription": "STRATEGIC_WEST_DIGNITY HEALTH",
       "ticketTpsmEffectiveDate": "2017-03-23",
       "ticketSubmissionDate": "2022-02-01",
       "ticketSubmitterName": "Akash Sangal",
       "ticketType": "Recon",
       "ticketQueue": "UHONE",
       "providerTin": "63845",
       "policyNumber": "D",
       "ticketStatus": "Under Review",
       "requestReasonAdjuster": "Paper or Electronic Check",
       "ticketSubmitterEmail": "akas@mail.com",
       "ticketSubmitterPhone": "1111111111",
       "amountOwned": "11.00",
       "amountOwnedFlag": "N",
       "ticketAssigneeName": "Agarwal, Sagar",
       "ticketAssigneeId": "sagarw79",
       "ticketConclusion": "On Hold",
       "ticketLastUpdated": "2022-02-01",
       "ticketLastUpdatedBy": "sagarw79",
       "claimSubmissionTransactionId": "N/A",
       "sourceApplication": "SDE",
       "serviceProviderLastName": "Mercy Gilbert Medical Center",
       "productId": "NESHADCP",
       "depedentSequenceNumber": "01",
       "stateOfIssue": "NE",
       "subscriberAddressLine1": "2807 MERRILL ST",
       "subscriberCity": "LINCOLN",
       "subscriberState": "NE",
       "subscriberZip5": "68503",
       "billingType": "131",
       "claimIndicator": "O",
       "claimRecievedDate": "2022-01-19",
       "ticketLastUpdatedName": "Agarwal, Sagar",
       "ticketTpsmCancelDate": "9999-12-31",
       "planBenefitTypeCode": "MD",
       "claimNetworkStatus": "O",
       "offshoreRestricted": "N",
       "isEmployeeRestricted": "N",
       "providerComments": "test",
       "platform": "UHONE",
       "payerId": "87726",
       "payerName": "HealthCare",
       "kafkaWorkflow": "COMPLETED",
       "providerRequestReason": "Paper or Electronic Check",
       "resubmissionCount": "0",
       "isClosed": "no",
       "assignedTopic": "kaas.g",
       "cu_ticketSubmittedDate_date": "2022-02-01 09:15:23",
       "cu_ticketLastUpdated_date": "2022-02-01 09:29:34.978",
       "cu_ticketNumber": "PIQ-9484478",
       "cu_totalAttachments_int": 0,
       "cu_resubmission_count_int": 0,
       "cu_bizAge_int": 1,
       "actualClaimNumber": "1234567890",
       "coverageType": "M",
       "facetsprovIdBilling": "99999999",
       "facetsprovIdRendering": "99999999",
       "ticketResubmissions": [
           {
               "openDate": "2022-02-01"
           }
       ],
       "ticketComments": [
           {
               "comment": "test",
               "category": "External",
               "createdBy": "Akash Sangal",
               "createDate": "2022-02-01",
               "reconRequestReason": "Paper or Electronic Check"
           },
           {
               "comment": "Received, working on request.",
               "category": "Internal",
               "createdBy": "Agarwal, Sagar",
               "ticketStatus": "Under Review",
               "createDate": "2022-02-01",
               "conclusion": "On Hold",
               "reconRequestReason": "Paper or Electronic Check",
               "createdById": "98765we"
           }
       ]
   }
}

下面是我试图从 API、

中提取数据的 C# 代码

我在 visual studio 2017 数据工具脚本组件中实现了这个。

               string connetionString = null;
                string sql = null;
                string serviceUrl = "http://URLLINK/reportingp/_doc/9484478";
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(serviceUrl);
                var serializer = new JavaScriptSerializer();

                // Add an Accept header for JSON format.   

                client.DefaultRequestHeaders.Accept.Add(newMediaTypeWithQualityHeaderValue("application/json"));
                  
                var plainTextBytes = System.Text.Encoding.UTF8.GetBytes("Username:Password");
                string val = System.Convert.ToBase64String(plainTextBytes);
                client.DefaultRequestHeaders.Add("Authorization", "Basic " + val);

                connetionString = "Data Source=Bharat_PC;Initial Catalog=Practice_OPS; Trusted_Connection=True;";

                string APIUrl = string.Format(serviceUrl);
                var response = client.GetAsync(APIUrl).Result;
                if (response.IsSuccessStatusCode)

                {

                    var result = response.Content.ReadAsStringAsync().Result;
                    MessageBox.Show(result);

                    var dt = serializer.Deserialize<Dictionary<string,string>[]>(result);

                    using (SqlConnection cnn = new SqlConnection(connetionString))```


In the MessageBox.Show(result); I am getting the output but in the next step while doing *serializer.Deserialize<Dictionary<string,string>[]>(result)* I am getting the error. Tried so many approaches but I am unable to fix it. Please help me with the solution.

你可以试试下面的方法

public class APIResponse
{
    public string _index { get; set; }
    public string _type { get; set; }
    public string _id { get; set; }
    public int _version { get; set; }
    public int _seq_no { get; set; }
    public int _primary_term { get; set; }
    public bool found { get; set; }
    public Source _source { get; set; }
}

public class Source
{
    public string claimNumber { get; set; }
    public string claimICN { get; set; }
    public string claimStatus { get; set; }
    public string claimType { get; set; }
    public string claimFirstDateService { get; set; }
    public string claimLastDateService { get; set; }
    public string isBehaviourHealth { get; set; }
    public string claimPatientAccountNumber { get; set; }
    public string claimBillingAmount { get; set; }
    public string claimPaidAmount { get; set; }
    public string claimCAE { get; set; }
    public string subscriberId { get; set; }
    public string memberId { get; set; }
    public string subscriberFirstName { get; set; }
    public string subscriberLastName { get; set; }
    public string subscriberDateOfBirth { get; set; }
    public string subscriberAddress { get; set; }
    public string patientFirstName { get; set; }
    public string patientLastName { get; set; }
    public string patientMiddleName { get; set; }
    public string patientDateOfBirth { get; set; }
    public string govProgramCode { get; set; }
    public string coverageStartDate { get; set; }
    public string coverageEndDate { get; set; }
    public string groupNumber { get; set; }
    public string relationshipCode { get; set; }
    public string sourceId { get; set; }
    public string billingMpin { get; set; }
    public string billingProviderName { get; set; }
    public string renderingMpin { get; set; }
    public string ticketNumber { get; set; }
    public string tpsmCode { get; set; }
    public string ticketTpsmIndicator { get; set; }
    public string ticketTpsmDescription { get; set; }
    public string ticketTpsmEffectiveDate { get; set; }
    public string ticketSubmissionDate { get; set; }
    public string ticketSubmitterName { get; set; }
    public string ticketType { get; set; }
    public string ticketQueue { get; set; }
    public string providerTin { get; set; }
    public string policyNumber { get; set; }
    public string ticketStatus { get; set; }
    public string requestReasonAdjuster { get; set; }
    public string ticketSubmitterEmail { get; set; }
    public string ticketSubmitterPhone { get; set; }
    public string amountOwned { get; set; }
    public string amountOwnedFlag { get; set; }
    public string ticketAssigneeName { get; set; }
    public string ticketAssigneeId { get; set; }
    public string ticketConclusion { get; set; }
    public string ticketLastUpdated { get; set; }
    public string ticketLastUpdatedBy { get; set; }
    public string claimSubmissionTransactionId { get; set; }
    public string sourceApplication { get; set; }
    public string serviceProviderLastName { get; set; }
    public string productId { get; set; }
    public string depedentSequenceNumber { get; set; }
    public string stateOfIssue { get; set; }
    public string subscriberAddressLine1 { get; set; }
    public string subscriberCity { get; set; }
    public string subscriberState { get; set; }
    public string subscriberZip5 { get; set; }
    public string billingType { get; set; }
    public string claimIndicator { get; set; }
    public string claimRecievedDate { get; set; }
    public string ticketLastUpdatedName { get; set; }
    public string ticketTpsmCancelDate { get; set; }
    public string planBenefitTypeCode { get; set; }
    public string claimNetworkStatus { get; set; }
    public string offshoreRestricted { get; set; }
    public string isEmployeeRestricted { get; set; }
    public string providerComments { get; set; }
    public string platform { get; set; }
    public string payerId { get; set; }
    public string payerName { get; set; }
    public string kafkaWorkflow { get; set; }
    public string providerRequestReason { get; set; }
    public string resubmissionCount { get; set; }
    public string isClosed { get; set; }
    public string assignedTopic { get; set; }
    public string cu_ticketSubmittedDate_date { get; set; }
    public string cu_ticketLastUpdated_date { get; set; }
    public string cu_ticketNumber { get; set; }
    public int cu_totalAttachments_int { get; set; }
    public int cu_resubmission_count_int { get; set; }
    public int cu_bizAge_int { get; set; }
    public string actualClaimNumber { get; set; }
    public string coverageType { get; set; }
    public string facetsprovIdBilling { get; set; }
    public string facetsprovIdRendering { get; set; }
    public List<TicketResubmission> ticketResubmissions { get; set; }
    public List<TicketComment> ticketComments { get; set; }
}

public class TicketComment
{
    public string comment { get; set; }
    public string category { get; set; }
    public string createdBy { get; set; }
    public string createDate { get; set; }
    public string reconRequestReason { get; set; }
    public string ticketStatus { get; set; }
    public string conclusion { get; set; }
    public string createdById { get; set; }
}

public class TicketResubmission
{
    public string openDate { get; set; }
}

并且在 HTTPRequest 成功响应块中

serializer.Deserialize<APIResponse>(result);