Mert
Mert

Reputation: 6582

json index checking and reaching values

    var jsonAdim = [];
    function openModal(index) {
        $("#<%= hidInputSenaryoIndex.ClientID %>").val(index);

        $("#senaryoAdimTable tbody").html("");

        jsonAdim = $("#<%= hidInputSenaryoAdim.ClientID %>").val();
        console.log(jsonAdim);
        for (i = 0; i < jsonAdim.length; i++) {
            console.log(jsonAdim[i]["Index"] + " -- " + index);
            if (jsonAdim[i]["Index"] == index + "") {
                var tr = "<tr><td>" + jsonAdim[i]["X"] + "</td><td>" + jsonAdim[i]["Y"] + "</td></tr>";
                $("#senaryoAdimTable tbody").append(tr);
            }
        }
    }

I get this to console >

[{"Index":"1","X":"0","Y":"a1"},{"Index":"1","X":"0","Y":"a2"}]
undefined -- 1

Question >

how can I reach this as json? > jsonAdim[i]["Index"]

Upvotes: 0

Views: 92

Answers (1)

Leo Nix
Leo Nix

Reputation: 2105

Looks like what contained in jsonAdim is JSON string, try using JSON.parse to get the objects out the string as follows: jsonAdimParsed = JSON.parse(jsonAdim);

check out how to use JSON.parse here

Upvotes: 1

Related Questions