在C#代码中序列化的序列化错误

发布于 2025-02-01 08:58:16 字数 6540 浏览 3 评论 0原文

我正在尝试从API中加载数据,该数据由C#中的JSON数据组成。但是,当我尝试使用 serialialser.deserialize<字典< string,string> []> 数据时,我会遇到错误。

以下是以下一个记录的示例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": "[email protected]",
       "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.

I am trying to load the data from the API which consists of JSON data in C#. But I am getting an error when I am trying to serializer.Deserialize<Dictionary<string,string>[]> the data.

Below is the sample API data for one record

   "_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": "[email protected]",
       "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"
           }
       ]
   }
}

Below is the C# Code which I am trying to pull the data from API,

I am implementing this in visual studio 2017 data tools script component.

               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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难忘№最初的完美 2025-02-08 08:58:16

尝试一下

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);

You can try it with below

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; }
}

And inside HTTPRequest Success response block

serializer.Deserialize<APIResponse>(result);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文