1

I found this awesome tip here at how to serialize a .Net DataTable into a Json String using Json.Net with the following code:

  return JsonConvert.SerializeObject(dtProdEv, Formatting.Indented);

I get the following result back:

[
  {
    "Col1": 2,
    "Col2": "\/Date(1292724000000-0200)\/",
    "Col3": 0,
    "Col4": 1,
    "Col5": "\/Date(1292772960760-0200)\/",
    "Col6": null,
    "Col7": null,
    "Col8": 0.0000,
    "Col9": 0,
    "Col10": 1
  },
  {
    "Col1": 2,
    "Col2": "\/Date(1292724000000-0200)\/",
    "Col3": 0,
    "Col4": 2,
    "Col5": "\/Date(1292773781763-0200)\/",
    "Col6": 3,
    "Col7": 1,
    "Col8": 0.0000,
    "Col9": 0,
    "Col10": 2
  }
]

My question is how can I iterate through this result using JQuery? I parse it into an Object using parseJSON, but then I'm stumped. Tks

Community
  • 1
  • 1
Pascal
  • 2,944
  • 7
  • 49
  • 78

1 Answers1

2

You can use $.each to iterate through the whole array.

See the live demo here.

// loop through the array of objects.
$.each(data ,function(i,item){

    // document.write(item["Col7"]); // print specific property


    // loop through the properties of each object.
    $.each(item, function(j, child){

        document.write(child); // print all the childs

    });

});
Zain Shaikh
  • 6,013
  • 6
  • 41
  • 66