C# का उपयोग करके json को API में कैसे परिवर्तित करें?

प्रोग्रामिंग


मेरे पास एक JSon है जिसके लिए मुझे D365 से C# में एक API बनाने की आवश्यकता है। क्या कोई पैकेज है जो C# में मेरी मदद कर सकता है? मैंने C# में पहले कभी कोई API नहीं बनाया है इसलिए यह मेरे लिए नया है। मुझे C# में नियंत्रण में क्या डालने की आवश्यकता है?

"d365EntityName": "account",
  "entityAlias": "account",
  "crmId": "0575ac39-a3c1-4d01-8cfa-4e52278c8665",
  "companyName": "AUTOLIV",
  "divisionId": null,
  "divisionName": null,
  "advisor": "",
  "bdRia": null,
  "bdRiaName": null,
  "billingLocationId": null,
  "billingLocationName": null,
  "clientGroupInt": null,
  "clientGroupName": null,
  "dateLost": null,
  "dba": "",
  "effectiveDate": null,
  "employeeBenefitsCoverageTypeInt": 867460000,
  "employeeBenefitsCoverageTypeName": "Group",
  "fein": "",
  "sicId": null,
  "sicName": null,
  "industryId": null,
  "industryName": null,
  "integrationMessage": "",
  "integrationStatus": "",
  "mainPhone": "",
  "numberOfEmployees": 23,
  "ownerName": "Tricia McCann",
  "regionInt": null,
  "regionName": null,
  "relationshipStatus": 3,
  "relationshipStatusName": "Green",
  "shippingLocationId": null,
  "shippingLocationName": null,
  "sourceId": "",
  "sourceSystem": null,
  "stateId": "99f9b75d-860b-ea11-a814-000d3a55d7ac",
  "stateName": "Arizona",
  "termedDate": null,
  "parentAccountId": "c39aaadf-dd6d-ea11-80db-005056912bbc",
  "parentAccountName": "DBA - St. Louis-MO (Centro Benefits Research LLC)",
  "companyTypeInt": 867460001,
  "companyTypeName": "Client",
  "brokerBooks": null,
  "products": null,
  "parentAccount": null,
  "name": null,
  "statusCodeInt": 1,
  "statusCodeName": "Active",
  "stateCodeInt": 0,
  "stateCodeName": "Active",
  "createdOn": "2023-07-10T09:22:08Z",
  "createdById": "c57e6623-2fbf-ed11-83ff-6045bdf05c47",
  "createdByName": "# D365 - Operational API User",
  "modifiedOn": "2023-11-17T07:40:19Z",
  "modifiedById": "c57e6623-2fbf-ed11-83ff-6045bdf05c47",
  "modifiedByName": "# D365 - Operational API User",
  "ownerId": "67f1f314-c74e-ea11-a813-000d3a55d7ac"

मैंने क्या प्रयास किया है:

सी#
<pre>namespace Benchmarking.Services.Api.Models
{
    public class AccountDetails
    {
        [JsonProperty("App")]
        public App App { get; set; }

        [JsonProperty("Name")]
        public string Name { get; set; }

        [JsonProperty("Account Id")]
        public Guid AccountId { get; set; }

        [JsonProperty("Number of Employees")]
        public int NumberOfEmployees { get; set; }

        [JsonProperty("State Name")]
        public string StateName { get; set; }

        [JsonProperty("Industry Code")]
        public string IndustryCode { get; set; }

        [JsonProperty("Partner")]
        public string Partner { get; set; }

        [JsonProperty("User")]
        public User User { get; set; }

        [JsonProperty("Products")]
        public List<Product> Products { get; set; }
    }

    public partial class App
    {
        [JsonProperty("name")]
        public string Name { get; set; }

        [JsonProperty("id")]
        public string Id { get; set; }
    }

    public partial class Product
    {
        [JsonProperty("Name")]
        public string ProductName { get; set; }

        [JsonProperty("Product Type")]
        public string ProductType { get; set; }

        [JsonProperty("Product Plan Type")]
        public string ProductPlanType { get; set; }

        [JsonProperty("InsurancePlans")]
        public List<InsurancePlan> InsurancePlans { get; set; }

        [JsonProperty("PlanDetails")]
        public List<PlanDetail> PlanDetails { get; set; }

        [JsonProperty("PlanRates")]
        public List<PlanRate> PlanRates { get; set; }
    }

    public class InsurancePlan
    {
        public string PlanName { get; set; }
        public List<PlanDetail> PlanDetails { get; set; }
        public List<PlanRate> PlanRates { get; set; }
    }

    public partial class PlanDetail
    {
        [JsonProperty("Name")]
        public string Name { get; set; }

        [JsonProperty("Innetwork")]
        public string Innetwork { get; set; }

        [JsonProperty("Category")]
        public string Category { get; set; }
    }

    public partial class PlanRate
    {
        [JsonProperty("Tier Type")]
        public string TierType { get; set; }

        [JsonProperty("Rate Type")]
        public string RateType { get; set; }

        [JsonProperty("Transaction Currency Id")]
        public string TransactionCurrencyId { get; set; }

        [JsonProperty("Employee Rate Money")]
        public decimal? EmployeeRateMoney { get; set; }

        [JsonProperty("Employerate Money")]
        public decimal? EmployerateMoney { get; set; }

        [JsonProperty("Employee Rate Percent")]
        public decimal? EmployeeRatePercent { get; set; }

        [JsonProperty("Employer Rate Percent")]
        public decimal? EmployerRatePercent { get; set; }

        [JsonProperty("Contribution Unit")]
        public object? ContributionUnit { get; set; }

        [JsonProperty("Monthly Premium")]
        public decimal? MonthlyPremium { get; set; }
    }

    public partial class User
    {
        [JsonProperty("name")]
        public string Name { get; set; }

        [JsonProperty("userid")]
        public string Userid { get; set; }
    }

समाधान 1

यहां एक टूल है जो इसे सरल बना देगा: JSON यूटिल्स: JSON से C#, VB.Net, SQL टेबल और Java जेनरेट करें[^].

मैंने JSON के साथ काम करने पर एक लेख भी लिखा है जिसमें अधिक टूल और तकनीकों की सूची है: >C# और VB में Newtonsoft.Json के साथ कार्य करना[^]

コメント

タイトルとURLをコピーしました