简体   繁体   English

遍历JSONResult中的数据

[英]Loop through data in a JSONResult

Is there a way to loop through JSON results using an index value instead of the key? 有没有一种方法可以使用索引值而不是键来遍历JSON结果? I would like to look through the json data result and grab the key and value that was sent over. 我想浏览json数据结果并获取发送过来的键和值。

eg 例如

 $.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>' 
        }     

       });

Assuming data is an array of dictionaries, you're close: 假设数据是一个字典数组,那么您将很接近:

 $.each(data, function(index, obj) {
      // then obj and data[index] both point to the nth entry in data
for (key in data) {
    key = the key name
    data[key] = the value
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM