deserealize array json and vb.net

0

Ajax sends an array containing values that the user selects from a checkbox set in this way

    $("#btnEnviarTelcel").click(function () {        
        var conjuntoFacturas=[];
        $("#form1 input[type=checkbox]").each(function (i) {
            if (this.checked) {

                conjuntoFacturas[i]= $(this).val();

            }
        });

        EnviarReporte(conjuntoFacturas);
        if (selected == '')
            alert('Debes seleccionar al menos una opción.');
        return false;
    });

    function EnviarReporte(varValorCheck) {

      var cargando = $("#muestraSeccion").html("<center><img  src='../Images/cargando1.gif' height='50px' width='50px'/><br/>Un momento por favor...<center>");

      $.ajax({
        type: 'POST',
        url: 'guardarEnvio',
        data: {
          "facturasEnvio": JSON.stringify(varValorCheck),

        },
        success: function(resultado) {

          $("#muestraSeccion").hide().html(resultado).fadeIn("fast");

        },
        error: function(jqXHR, textStatus, errorThrown) {
          console.log(jqXHR, textStatus, errorThrown);
          if (jqXHR.status === 0) {

            alert('Not connect: Verify Network.=(');

          } else if (jqXHR.status == 404) {

            alert('Requested page not found [404].');

          } else {

            alert('Uncaught Error: ' + jqXHR.responseText);

          }

        }
      });
    }

later on the page "saveAnswer" I retrieve the array like this:

Dim grupoFacturas=Request.Form("facturasEnvio") Dim result = JsonConvert.DeserializeObject(grupoFacturas) Response.Write(result)

and it shows me the next result

but how can I get the values individually? since I would be doing an update for each value returned by the array

    
asked by Ivxn 02.07.2016 в 00:34
source

1 answer

1

In the click event, I recommend adding the elements in the array using the push function, otherwise you leave spaces with value in null , as you see in your example, something that will be annoying to process the array on the server.

$("#form1 input[type=checkbox]").each(function (i) {
  if (this.checked) {
    conjuntoFacturas.push($(this).val());
  }
});

Finally in VB.NET he deserializes the list using

Dim result = JsonConvert.DeserializeObject(Of List(Of String))(grupoFacturas)
    
answered by 02.07.2016 / 02:08
source