Comment convertir un json en API en utilisant C# ?

la programmation

[ad_1]

J’ai un JSon pour lequel je dois créer une API en C# à partir de D365. Existe-t-il des packages qui peuvent m’aider en C# ? Je n’ai jamais créé d’API auparavant en C#, c’est donc nouveau pour moi. Que dois-je mettre dans un contrôle en 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"

Ce que j’ai essayé :

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

Solution 1

Voici un outil qui simplifiera les choses : Utilitaires JSON : générer C#, VB.Net, SQL Table et Java à partir de JSON[^].

J’ai également écrit un article sur l’utilisation de JSON qui répertorie davantage d’outils et de techniques : >Travailler avec Newtonsoft.Json en C# et VB[^]

[ad_2]

コメント

Titre et URL copiés