Search code examples
jqueryasp.net-mvc-3viewdata

how to read data from json to View using jquery mvc


I have the following data in an array.

[{"FirstName":"Nancy","LastName":"Davolio","Title":"Sales Representative"},
{"FirstName":"Andrew","LastName":"Fuller","Title":"Vice President, Sales"}]

I want to present this data using jquery into a table like this :

 <table id="employee">
 <tr>
 <td>Nancy</td>
 <td>Davolio</td>
 <td>Sales Representative</td>
 ...
 </table>

Solution

  • similar

    $(document).ready(function() {
          var jsonp = '[{"Lang":"jQuery","ID":"1"},{"Lang":"C#","ID":"2"}]';
          var lang = '';
          var obj = $.parseJSON(jsonp);
          $.each(obj, function() {
              lang += this['Lang'] + "<br/>";
          });
          $('span').html(lang);
        });​