2016-10-16 14 views
1

私は次のJSONを持っています。私はWebサービスを取得しています。Newtonsoft.Json.JsonSerializationException:現在のJSONオブジェクトを逆シリアル化できません

{ 
    "CodigoRetorno": 0, 
    "Mensagem": "Sucesso", 
    "Dados": { 
    "Agendas": [ 
     { 
     "CodigoClinica": 6259, 
     "CodigoConvenio": 3078, 
     "CodigoPaciente": 96589, 
     "CodigoProfissional": 9732, 
     "CodigoTipoAgendamento": 1, 
     "CodigoProcedimento": 2047, 
     "DataAgenda": "2016-10-10T00:00:00", 
     "DataAlteracao": "2016-10-10T12:08:44.367", 
     "DataInclusao": "2016-10-10T12:03:23.25", 
     "HoraFim": "14:25:00", 
     "HoraInicio": "14:00:00", 
     "Observacao": null, 
     "Status": 1, 
     "StatusDescricao": "Não Confirmado", 
     "Cor": "#659be0", 
     "NomePaciente": "Murilo neandro", 
     "NomeProfissional": "Fernanda valente", 
     "NomeProcedimento": null, 
     "CodigoProfissionalUsuario": 10260, 
     "Codigo": 291193, 
     "Excluido": false 
     } 
    ], 
    "Profissionais": [ 
     { 
     "Nome": "Fernanda valente", 
     "Apelido": null, 
     "CNPJOuCPF": null, 
     "CodigoClinica": 6259, 
     "CodigoTipoDocProfissional": null, 
     "Documento": null, 
     "CEP": null, 
     "Endereco": null, 
     "Complemento": null, 
     "Numero": null, 
     "Bairro": null, 
     "Municipio": null, 
     "UF": null, 
     "CodigoTipoProfissional": 2, 
     "DocumentoUF": "SP", 
     "Email": "[email protected]", 
     "DataNascimento": null, 
     "Sexo": null, 
     "Observacao": null, 
     "Faltas": 0, 
     "Atendimentos": 0, 
     "CodigoConselho": 1, 
     "CRM": "455451", 
     "Codigo": 9732, 
     "Excluido": false 
     } 
    ], 
    "Telefones": [ 
     { 
     "CodigoClinica": 6259, 
     "NumeroTelefone": "65955292552", 
     "CodigoTipoTelefone": 0, 
     "Codigo": 5170, 
     "Excluido": false 
     } 
    ], 
    "Convenios": [ 
     { 
     "CodigoClinica": 6259, 
     "CodigoSequencial": 1, 
     "Nome": "Particular", 
     "Cor": "#2d8b46", 
     "Codigo": 3078, 
     "Excluido": false 
     } 
    ], 
    "Pacientes": [ 
     { 
     "Bairro": null, 
     "CEP": null, 
     "CPF": null, 
     "Celular": "89589589859", 
     "CodigoClinica": 6259, 
     "Complemento": null, 
     "Email": null, 
     "Endereco": null, 
     "Municipio": null, 
     "Nome": "Murilo neandro", 
     "Numero": null, 
     "Telefone": "98985859859", 
     "UF": null, 
     "DataNascimento": null, 
     "Faltas": null, 
     "Sexo": " ", 
     "LiberaAtendimento": false, 
     "Codigo": 96589, 
     "Excluido": false 
     } 
    ], 
    "FinanceiroCategorias": [ 
     { 
     "CodigoClinica": 6259, 
     "Descricao": "Ajustes", 
     "Codigo": 1, 
     "Excluido": false 
     } 
    ], 
    "FinanceiroSubCategorias": [ 
     { 
     "CodigoClinicaCategoria": 6, 
     "CodigoClinica": 6259, 
     "Descricao": "Procedimento", 
     "Tipo": "R", 
     "Cor": "#659be0", 
     "Codigo": 63, 
     "Excluido": false 
     } 
    ], 
    "FormaPagamentos": [ 
     { 
     "CodigoClinica": 6259, 
     "CodigoFormaPagamento": 1, 
     "CodigoFormaPagamentoPai": null, 
     "CodigoUsuario": 1, 
     "Nome": "CAIXA", 
     "Ativo": 1, 
     "DataAlteracao": "2016-10-10T11:49:56.41", 
     "Codigo": 86, 
     "Excluido": false 
     } 
    ], 
    "Bairro": "Vila Ana Maria", 
    "CEP": "14026220", 
    "CNES": null, 
    "CNPJCPF": "65625656256256", 
    "Complemento": null, 
    "Email": null, 
    "Endereco": "Rua Raul Peixoto", 
    "Municipio": "Ribeirão Preto", 
    "Nome": "Viper Clinicas", 
    "Numero": "630", 
    "UF": "SP", 
    "HoraInicio": "08:00:00", 
    "HoraFim": "20:00:00", 
    "Latitude": "-21.2103565", 
    "Longitude": "-47.8183606", 
    "Codigo": 6259, 
    "Excluido": false 
    } 
} 

は私だけ私は私が私の状況

のより良い理解に使用していたクラスを置く Error

下の画像のようにエラーが発生している

var clinicas = JsonConvert.DeserializeObject<List<Clinica>>(response.Content); 

をデシリアライズするためのコードを使用しました

public class Clinica : ModelBase 
    { 
     private string _nome; 
     private double _latitude; 
     private double _longitude; 

     public string Nome 
     { 
      get 
      { 
       return _nome; 
      } 
      set 
      { 
       _nome = value; 
       RaisedPropertyChanged(() => Nome); 
      } 
     } 

     public double Latitude 
     { 
      get 
      { 
       return _latitude; 
      } 
      set 
      { 
       _latitude = value; 
       RaisedPropertyChanged(() => Latitude); 
      } 
     } 

     public double Longitude 
     { 
      get 
      { 
       return _longitude; 
      } 
      set 
      { 
       _longitude = value; 
       RaisedPropertyChanged(() => Longitude); 
      } 
     } 


    } 

どのようにすれば解決できますかこれは?

+1

JSONは、あなたがそれをデシリアライズしようとしているためにタイプと一致していません。程遠い。 – David

+0

Dadosの名前のClinicaクラスの名前を変更しましたが、同じエラーが発生しました。私はちょうど名前のプロパティ、緯度、経度が必要です – Duk

答えて

0

いつかのように:

var example = JsonConvert.DeserializeObject<Example>(jsonString); 
Console.WriteLine(example.Dados.Latitude); 

あなたのクラスモデルは、このように見えたの場合:

public class Agenda 
{ 
    public int CodigoClinica { get; set; } 
    public int CodigoConvenio { get; set; } 
    public int CodigoPaciente { get; set; } 
    public int CodigoProfissional { get; set; } 
    public int CodigoTipoAgendamento { get; set; } 
    public int CodigoProcedimento { get; set; } 
    public DateTime DataAgenda { get; set; } 
    public DateTime DataAlteracao { get; set; } 
    public DateTime DataInclusao { get; set; } 
    public string HoraFim { get; set; } 
    public string HoraInicio { get; set; } 
    public object Observacao { get; set; } 
    public int Status { get; set; } 
    public string StatusDescricao { get; set; } 
    public string Cor { get; set; } 
    public string NomePaciente { get; set; } 
    public string NomeProfissional { get; set; } 
    public object NomeProcedimento { get; set; } 
    public int CodigoProfissionalUsuario { get; set; } 
    public int Codigo { get; set; } 
    public bool Excluido { get; set; } 
} 

public class Profissionai 
{ 
    public string Nome { get; set; } 
    public object Apelido { get; set; } 
    public object CNPJOuCPF { get; set; } 
    public int CodigoClinica { get; set; } 
    public object CodigoTipoDocProfissional { get; set; } 
    public object Documento { get; set; } 
    public object CEP { get; set; } 
    public object Endereco { get; set; } 
    public object Complemento { get; set; } 
    public object Numero { get; set; } 
    public object Bairro { get; set; } 
    public object Municipio { get; set; } 
    public object UF { get; set; } 
    public int CodigoTipoProfissional { get; set; } 
    public string DocumentoUF { get; set; } 
    public string Email { get; set; } 
    public object DataNascimento { get; set; } 
    public object Sexo { get; set; } 
    public object Observacao { get; set; } 
    public int Faltas { get; set; } 
    public int Atendimentos { get; set; } 
    public int CodigoConselho { get; set; } 
    public string CRM { get; set; } 
    public int Codigo { get; set; } 
    public bool Excluido { get; set; } 
} 

public class Telefone 
{ 
    public int CodigoClinica { get; set; } 
    public string NumeroTelefone { get; set; } 
    public int CodigoTipoTelefone { get; set; } 
    public int Codigo { get; set; } 
    public bool Excluido { get; set; } 
} 

public class Convenio 
{ 
    public int CodigoClinica { get; set; } 
    public int CodigoSequencial { get; set; } 
    public string Nome { get; set; } 
    public string Cor { get; set; } 
    public int Codigo { get; set; } 
    public bool Excluido { get; set; } 
} 

public class Paciente 
{ 
    public object Bairro { get; set; } 
    public object CEP { get; set; } 
    public object CPF { get; set; } 
    public string Celular { get; set; } 
    public int CodigoClinica { get; set; } 
    public object Complemento { get; set; } 
    public object Email { get; set; } 
    public object Endereco { get; set; } 
    public object Municipio { get; set; } 
    public string Nome { get; set; } 
    public object Numero { get; set; } 
    public string Telefone { get; set; } 
    public object UF { get; set; } 
    public object DataNascimento { get; set; } 
    public object Faltas { get; set; } 
    public string Sexo { get; set; } 
    public bool LiberaAtendimento { get; set; } 
    public int Codigo { get; set; } 
    public bool Excluido { get; set; } 
} 

public class FinanceiroCategoria 
{ 
    public int CodigoClinica { get; set; } 
    public string Descricao { get; set; } 
    public int Codigo { get; set; } 
    public bool Excluido { get; set; } 
} 

public class FinanceiroSubCategoria 
{ 
    public int CodigoClinicaCategoria { get; set; } 
    public int CodigoClinica { get; set; } 
    public string Descricao { get; set; } 
    public string Tipo { get; set; } 
    public string Cor { get; set; } 
    public int Codigo { get; set; } 
    public bool Excluido { get; set; } 
} 

public class FormaPagamento 
{ 
    public int CodigoClinica { get; set; } 
    public int CodigoFormaPagamento { get; set; } 
    public object CodigoFormaPagamentoPai { get; set; } 
    public int CodigoUsuario { get; set; } 
    public string Nome { get; set; } 
    public int Ativo { get; set; } 
    public DateTime DataAlteracao { get; set; } 
    public int Codigo { get; set; } 
    public bool Excluido { get; set; } 
} 

public class Dados 
{ 
    public IList<Agenda> Agendas { get; set; } 
    public IList<Profissionai> Profissionais { get; set; } 
    public IList<Telefone> Telefones { get; set; } 
    public IList<Convenio> Convenios { get; set; } 
    public IList<Paciente> Pacientes { get; set; } 
    public IList<FinanceiroCategoria> FinanceiroCategorias { get; set; } 
    public IList<FinanceiroSubCategoria> FinanceiroSubCategorias { get; set; } 
    public IList<FormaPagamento> FormaPagamentos { get; set; } 
    public string Bairro { get; set; } 
    public string CEP { get; set; } 
    public object CNES { get; set; } 
    public string CNPJCPF { get; set; } 
    public object Complemento { get; set; } 
    public object Email { get; set; } 
    public string Endereco { get; set; } 
    public string Municipio { get; set; } 
    public string Nome { get; set; } 
    public string Numero { get; set; } 
    public string UF { get; set; } 
    public string HoraInicio { get; set; } 
    public string HoraFim { get; set; } 
    public string Latitude { get; set; } 
    public string Longitude { get; set; } 
    public int Codigo { get; set; } 
    public bool Excluido { get; set; } 
} 

public class Example 
{ 
    public int CodigoRetorno { get; set; } 
    public string Mensagem { get; set; } 
    public Dados Dados { get; set; } 
} 
0
  1. JSONはオブジェクトであり、配列ではありません。だからオブジェクトのList<>ではなくオブジェクトにそれを逆シリアル化します。
  2. 逆シリアル化するクラスは、JSONの構造と一致している必要があります。それ以外の場合は、プロパティを一致させることはできません。

このような何か:

public class Clinica : ModelBase 
{ 
    private Dados _dados; 

    public string Dados 
    { 
     get 
     { 
      return _dados; 
     } 
     set 
     { 
      _dados = value; 
      RaisedPropertyChanged(() => Dados); 
     } 
    } 
} 

public class Dados 
{ 
    // properties for Nome, Latitude, Longitude 
} 

基本的には、シリアライザはあなたには、いくつかの他のプロパティの内部プロパティは、ここで使用したいことを知っているつもりはありません。構造を含む構造を含む構造は一致しなければならない。

関連する問題