循环遍历JSONResult中的数据

时间:2011-08-18 22:39:49

标签: javascript asp.net-mvc json

有没有办法使用索引值代替键来循环JSON结果? 我想查看json数据结果并获取发送的密钥和值。

e.g。

 $.get('/Home/GetTypes', function (data) 
      {
       $.each(function(index) {
           //Just as an example I know this will not work. Thanks
         '<a class="p-button" href="/Wizard/Create/" + data[index][value] + " '">' + data[index][key] + '</a>' 
        }     

       });

2 个答案:

答案 0 :(得分:0)

假设数据是一个字典数组,那你就近了:

 $.each(data, function(index, obj) {
      // then obj and data[index] both point to the nth entry in data

答案 1 :(得分:0)

for (key in data) {
    key = the key name
    data[key] = the value
}
相关问题