Return with several json with jquery .net

1

I need to return to json a json, or rather several json, being city, neighborhood, state, parents, each being a json in the same method, but as it is not possible to do several returns I put the obj list up in one list list.

        List < List<String> > final = new List < List<String> >();
        final.Add(cidade);
        final.Add(bairro);
        final.Add(estado);
        final.Add(pais);

just below return the json from the final list

        return Json(final, JsonRequestBehavior.AllowGet);

But when I display the data in ajax, when I access the data position [1] or 2 ..., it picks up as a whole list and not as a json, I think it returned the json's only positions 0.1 , 2 ... and not what's inside it, how do you return that data as json

<script>
$(document).ready(function () {
     cidade.change(function () {
        $(function () {
            $('#loading').html('<img  
            $.ajax({
                dataType: "json",
                type: "GET",
                url: "GetDados",
                data: { Cidade: cidade.val() },
                success: function (dados) 
                $(dados).each(function (i) {
                   alert(dados[1]);
                    });
                 }
            });
        });
    });
})

</script>
    
asked by anonymous 02.08.2016 / 22:46

1 answer

2

controller:

var result = new { cidade, bairro, estado, pais };
return Json (result, JsonRequestBehavior.AllowGet);

"result" is an anonymous object

javascript:

<script>
$(document).ready(function () {
     cidade.change(function () {
        $(function () {
        $('#loading').html('<img  
        $.ajax({
            dataType: "json",
            type: "GET",
            url: "GetDados",
            data: { Cidade: cidade.val() },
            success: function (dados) {
               alert(dados.cidade);
             }
        });
    });
});
</script>
    
06.08.2016 / 16:18