开发者

Loop through data in a JSONResult

开发者 https://www.devze.com 2023-03-29 07:37 出处:网络
Is there a way to loop through JSON results us开发者_StackOverflow社区ing an index value instead of the key?

Is there a way to loop through JSON results us开发者_StackOverflow社区ing an index value instead of the key? I would like to look through the json data result and grab the key and value that was sent over.

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

       });


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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消