0

私は通常、オブジェクトをループして asp.net mvc で Json オブジェクトを操作し、次のような結果を表示します。

$.each(data, function (key, val) { 

                        // Format the text to display. 
                        var str = val.id + ': $' + val.packageName; 

                        // Add a list item for the product. 
                        $('<li/>', { text: str }) 
                        .appendTo($('#products')); 

しかし、ある種の階層を含む次の形式でJsonオブジェクトを返すWebサービスに出くわしました:-

{
  "total":3,
  "desc":false,
  "sort":"name",
  "start":0,
  "data":
  [
    {"id":"hdc_v1001#1#hdc_certification_process",
      "packageName":"halal certification",
      "name":"HDC Certification Process",
      "packageId":"hdc_v1001",
      "label":"HDC Certification Process ver 1",
      "version":"1"},
    {"id":"mdec_v1002#12#mdec_wp1",
      "packageName":"Mdec Work Progress",
      "name":"mdec_wp1",
      "packageId":"mdec_v1002",
      "label":"mdec_wp1 ver 12",
      "version":"12"},
    {"id":"mora#5#mora_new_application",
      "packageName":"MORA Halal Certification",
      "name":"MORA New Application",
      "packageId":"mora",
      "label":"MORA New Application ver 5",
      "version":"5"}
  ]
}

この場合、Jsonオブジェクトをループしてその値を表示するにはどうすればよいですか? よろしくお願いします

4

1 に答える 1

1
myJsonObject = {
  "total":3,
  "desc":false,
  "sort":"name",
  "start":0,
  "data":
  [
    {"id":"hdc_v1001#1#hdc_certification_process",
      "packageName":"halal certification",
      "name":"HDC Certification Process",
      "packageId":"hdc_v1001",
      "label":"HDC Certification Process ver 1",
      "version":"1"},
    {"id":"mdec_v1002#12#mdec_wp1",
      "packageName":"Mdec Work Progress",
      "name":"mdec_wp1",
      "packageId":"mdec_v1002",
      "label":"mdec_wp1 ver 12",
      "version":"12"},
    {"id":"mora#5#mora_new_application",
      "packageName":"MORA Halal Certification",
      "name":"MORA New Application",
      "packageId":"mora",
      "label":"MORA New Application ver 5",
      "version":"5"}
  ]
};
$.each(myJsonObject.data, function (key, val) { 

                    // Format the text to display. 
                    var str = val.id + ': $' + val.packageName; 

                    // Add a list item for the product. 
                    $('<li/>', { text: str }) 
                    .appendTo($('#products')); 
}
于 2012-10-09T10:18:34.140 に答える