gpt4 book ai didi

javascript - 尝试循环遍历 Json 对象,该对象内部有更多对象和对象数组

转载 作者:行者123 更新时间:2023-11-28 05:41:56 25 4
gpt4 key购买 nike

我一直在用头撞墙试图循环遍历这个 json 文件。

当我控制台记录它时,它说响应是一个对象,数据是一个对象,saleItemCategories 是一个数组,其中有四个对象,第一个是车辆,它是项目对象的数组。

基本上我试图从这些项目对象中获取各种值。此时,我只是寻求深入了解此级别的帮助。

"Response":{
"data":{
"vendorHash":2668878854,
"nextRefreshDate":"9999-12-31T23:59:59.999Z",
"enabled":true,
"saleItemCategories":[
{
"categoryIndex":2,
"categoryTitle":"Vehicles",
"saleItems":[
{
"item":{
"itemHash":3645385954,
"bindStatus":0,
"isEquipped":false,
"itemInstanceId":"0",
"itemLevel":0,
"stackSize":1,
"qualityLevel":0,
"stats":[
{
"statHash":3017642079,
"value":35,
"maximumValue":100
}
],
"primaryStat":{
"statHash":1501155019,
"value":150,
"maximumValue":0
},
"canEquip":true,
"equipRequiredLevel":0,
"unlockFlagHashRequiredToEquip":2166136261,
"cannotEquipReason":0,
"damageType":0,
"damageTypeHash":0,
"damageTypeNodeIndex":-1,
"damageTypeStepIndex":-1,
"progression":{
"dailyProgress":0,
"weeklyProgress":0,
"currentProgress":0,
"level":0,
"step":0,
"progressToNextLevel":0,
"nextLevelAt":0,
"progressionHash":0
},
"talentGridHash":2064730449,
"nodes":[
{
"isActivated":true,
"stepIndex":0,
"state":10,
"hidden":false,
"nodeHash":0
}
],
"useCustomDyes":true,
"artRegions":{

},
"isEquipment":true,
"isGridComplete":false,
"perks":[
{
"iconPath":"/common/destiny_content/icons/b65252b2007607955aa1fc3026154c8c.png",
"perkHash":4091143788,
"isActive":true
}
],
"location":3,
"transferStatus":0,
"locked":false,
"lockable":false,
"objectives":[

],
"state":0
},
"vendorItemIndex":30,
"itemStatus":0,
"costs":[
{
"itemHash":2534352370,
"value":175
}
],
"requiredUnlockFlags":[

],
"unlockStatuses":[

],
"failureIndexes":[

]
},

我尝试将每个 Response 作为对象循环,然后将每个数据作为对象循环,然后我尝试循环 saleItemCategories 数组,但这通常是它中断的地方

最佳答案

var json = "your data";

var itemCategories = json.Response.data.saleItemCategories;

for (int i = 0; i < itemCategories.length; i++) {
var categoryItems = itemCategories[i].saleItems;
console.log(categoryItems.categoryTitle);

for (int j = 0; j < categoryItems.length; j++) {
var categoryItem = categoryItems[j];
var categoryItemStats = categoryItem.stats;

console.log(categoryItem.itemHash);

for (var k = 0; k < categoryItemStats; k++) {
var categoryItemStat = categoryItemStats[k];

console.log(categoryItemStat);
}
}
}

关于javascript - 尝试循环遍历 Json 对象,该对象内部有更多对象和对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38851654/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com