Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

268
Visualizações
JsonSerializer.Deserialize won't work in class C#

I am trying everything I can but the object is not getting deserialized, I tried almost all the possible solutions to the problem but nothing is working, if someone can help that would be great. please see below is the code snippet for the code it always returns a null value to me.

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 Respostas
Responde à pergunta

0

you have a bug in your classes, all your setters are private, but they should be public. all properties should be like this

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

or you can keep the setters private but create a constructor

 public EnrollmentExtension(string enrollmentType, ... and so on, string workflowType) { _enrollmentType=enrollmentType; _workflowType=workflowType; ... and so on }
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda