-1
I’m trying to ride a Json
in the following structure:
"contatos":[{"contato":{"sequencia":"2046","codigo":"2046","nome":"teste balizador","tipo_pessoa":"PJ","cpf_cnpj":"32337775000143","ie":"","im":"","rg":"","tipo_negocio":"","endereco":"Rua Três Pontas","numero":"440","complemento":"","bairro":"Aparecida","cidade":"","cep":"30710-560","uf":"","pais":"","contatos":"Tiny","fone":"(31) 2526-0565","fax":"","celular":"","email":"[email protected]","id_vendedor":"4","situacao":"A","obs":""}}]
but when mounting the Json
my file is without the contatos
:
{"contato":{"sequencia":"2046","codigo":"2046","nome":"teste balizador","tipo_pessoa":"PJ","cpf_cnpj":"32337775000143","ie":"","im":"","rg":"","tipo_negocio":"","endereco":"Rua Três Pontas","numero":"440","complemento":"","bairro":"Aparecida","cidade":"","cep":"30710-560","uf":"","pais":"","contatos":"Tiny","fone":"(31) 2526-0565","fax":"","celular":"","email":"[email protected]","id_vendedor":"4","situacao":"A","obs":""}}
I believe I’m forgetting something I haven’t figured out yet.
follows the excerpt from my code:
public class contato
{
public string sequencia { get; set; }
public string codigo { get; set; }
...
public string obs { get; set; }
}
public class Contatos
{
public contato contato { get; set; }
}
var contato = new contato
{
sequencia = cliente.CodCliente.ToString(),
codigo = cliente.CodCliente.ToString(),
...
obs = cliente.Observacoes
};
var contatosList = new Contatos() { contato = contato };
var contatos = new JavaScriptSerializer().Serialize(contatosList);
Your code is missing standardization of class nomenclature. Usually with initial capitalization. are you creating a variable and instantiating itself? var contact = new contact
– Rebeca Nonato
What’s the point of creating a Contacts class from contact?
– Rebeca Nonato
was the way I got to get to the Json pattern, I’m analyzing the code and redoing it more clearly and correctly.
– Gustavo .NET
Does Your Json have to be in the first structure? Some front rule? In this case it is a Contacts that has a Contact object list. Right?
– Rebeca Nonato
exactly, because it may happen that within contacts have more than one example contact:
– Gustavo .NET
"contacts":[{"contact":{"sequence":"2046","code":"2046","name":"balizer test","tipo_person":"PJ","cpf_cnpj":"32337775000143","ie":""","im":"","rg":"","tipo_negocio":"""},"contact":{"sequence"": .....}
– Gustavo .NET
You do not need to run the wheel twice. Your list vc declares like this List<Contact> Contacts = new List<Contact>();
– Rebeca Nonato
Fills contact = new Contact {} and then Contacts.Add(contact);
– Rebeca Nonato