【问题标题】:Iterate DataTable serialized through Json.Net in jQuery在jQuery中迭代通过Json.Net序列化的DataTable
【发布时间】:2011-05-27 22:48:00
【问题描述】:

我在如何使用 Json.Net 将 .Net DataTable 序列化为 Json 字符串时发现了这个很棒的技巧 here,代码如下:

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

我得到以下结果:

[
  {
    "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
  }
]

我的问题是如何使用 JQuery 遍历这个结果?我使用parseJSON 将其解析为一个对象,但后来我被难住了。 提示

【问题讨论】:

    标签: .net jquery json json.net


    【解决方案1】:

    您可以使用$.each 遍历整个数组。

    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
    
        });
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-05
      • 2021-10-20
      • 2019-05-20
      • 2012-06-23
      • 2010-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多