How would you do to convert this Json to Objects in C # [duplicate]

1

How to convert this JSON to a C # object?

{
   "Maquinas":{
      "Maquina1":[
         {
            "comando":"Get",
            "enderecoip":"192.168.254.221",
            "port":"3000",
            "usuario":"teste",
            "Senha":"123456"
         },
         {
            "comando":"sendFuncionarios",
            "enderecoip":"192.168.140.221",
            "port":"3000",
            "usuario":"teste fabrica",
            "Senha":"111111",
            "funcionariosHA":[
               {
                  "nome":"Daril Mont",
                  "pis":"1234567891",
                  "verdigital":false,
                  "codigo":30
               },
               {
                  "nome":"Mont Daril",
                  "pis":"62633975303",
                  "verdigital":true,
                  "codigo":31
               }
            ]
         },
         {
            "comando":"sendEmpresa",
            "enderecoip":"192.168.140.221",
            "port":"3000",
            "usuario":"fabrica",
            "Senha":"123456",
            "EmpresaHexaAdv":[
               {
                  "razaoSocial":"Oficina de Computadores",
                  "tipoCadastro":"CNPJ",
                  "CPF":"",
                  "CNPJ":"20330852471",
                  "endereco":"R. Mariana, 265",
                  "CEI":""
               }
            ]
         }
      ],
      "Maquina2":[
         {
            "comando":"Get",
            "enderecoip":"192.168.210.223",
            "port":"51000",
            "cpf":"13556285630"
         },
         {
            "comando":"sendFuncionarios",
            "enderecoip":"192.168.210.223",
            "port":"51000",
            "cpf":"13556285630",
            "funcionariosInnerREP":[
               {
                  "nome":"Dorval Miguel",
                  "pis":"1234567891",
                  "verdigital":false,
                  "codigo":30,
                  "senha":"0030"
               },
               {
                  "nome":"Leticia do Carmo",
                  "pis":"62633975303",
                  "verdigital":true,
                  "codigo":31,
                  "senha":"0031"
               }
            ]
         },
         {
            "comando":"sendEmpresa",
            "enderecoip":"192.168.210.223",
            "port":"51000",
            "cpf":"13556285630",
            "EmpresaInnerREP":[
               {
                  "razaoSocial":"Oficina de Computadores",
                  "tipoCadastro":"CNPJ",
                  "CPF":"",
                  "CNPJ":"20330852471",
                  "endereco":"Rua abacate 25",
                  "CEI":""
               }
            ]
         }
      ]
   }
}
    
asked by anonymous 04.01.2018 / 17:22

1 answer

0

One easy way for you to create a class that represents a Json (in Dotnet 4.5 or higher) is to copy Json content to the clipboard, create a new class, and use the Edit > Paste Special > Paste JSON Classes . The IDE will automatically create one or more classes that represents your JSON structure.

Having this class you can easily deserialize a JSON string into an instance of this class using JSON.NET . Here's an example:

public static MeuObjeto Deserializar(string json)
    {
        return JsonConvert.DeserializeObject<MeuObjeto>(json);
    }
    
04.01.2018 / 20:52