Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

266
Views
JsonSerializer.Deserialize no funcionará en la clase C#

Estoy intentando todo lo que puedo, pero el objeto no se deserializa, probé casi todas las soluciones posibles al problema, pero nada funciona, si alguien puede ayudar, sería genial. vea a continuación el fragmento de código para el código que siempre me devuelve un valor nulo.

 using System; using System.Text.Json; namespace ConsoleApp8 { class Program { static void Main(string[] args) { var a = "{\"enrollmentType\":\"draft\",\"emrName\":\"accuro\",\"emrVersion\":\"v1\",\"workflowType\":\"coordinator\"}"; var x = "{\"enrollmentType\":\"draft\",\"emrName\":\"accuro\",\"emrVersion\":\"v1\",\"workflowType\":\"coordinator\"}"; string json = @"{""id"":10,""name"":""Name"",""revisionDate"":1390293827000}"; var ed = JsonSerializer.Deserialize<EnrollmentExtension>(x); //.Replace("'", "\"") if (!string.IsNullOrWhiteSpace(ed.emrName)) { } } } public class EnrollmentExtension { #region MyRegion private string _emrName; private string _emrVersion; private string _workflowType; private string _enrollmentType; public bool IsDraft() { return (string.Compare(_enrollmentType, "draft", true) == 0); } #endregion public string enrollmentType { get { return _enrollmentType; } private set { _enrollmentType = value; } } public string workflowType { get { return _workflowType; } private set { _workflowType = value; } } public string emrVersion { get { return _emrVersion; } private set { _emrVersion = value; } } public string emrName { get { return _emrName; } private set { _emrName = value; } } public void SetWorkflowType(string workFlowType) { _workflowType = workFlowType; } } public class Test { public EnrollmentExtension myprop { get; set; } } }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

tiene un error en sus clases, todos sus setters son privados, pero deberían ser públicos. todas las propiedades deberían ser así

 public string enrollmentType { get { return _enrollmentType; } set { _enrollmentType = value; } }

o puede mantener los setters privados pero crear un constructor

 public EnrollmentExtension(string enrollmentType, ... and so on, string workflowType) { _enrollmentType=enrollmentType; _workflowType=workflowType; ... and so on }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!