我从如下所示的API得到响应。例如,如何使用jQuery访问“ appName”的值来遍历结果?

var apps =
{
  358899126:
   { appId: 358899126,
     appName: 'Tagged -Chill, Chat & Go Live!',
     primaryCategoryName: 'Social Networking' },
  359917414:
   { appId: 359917414,
     appName: 'Solitaire',
     primaryCategoryName: 'Games' }
}

最佳答案

您可以使用Object.keys获取每个对象的键,然后使用方括号语法获取实际的对象,如下所示:



var apps =
{
  358899126:
   { appId: 358899126,
     appName: 'Tagged -Chill, Chat & Go Live!',
     primaryCategoryName: 'Social Networking' },
  359917414:
   { appId: 359917414,
     appName: 'Solitaire',
     primaryCategoryName: 'Games' }
}

Object.keys(apps).forEach((key) => {
  let obj = apps[key];
  console.log(obj.appName);
});

关于jquery - 遍历JSON响应对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47764969/

10-12 03:53