簡體   English   中英

試圖在Json對象中循環,對象中包含更多對象

[英]Trying to loop through Json Object that has more objects inside with arrays of objects

我一直在試圖繞過這個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);
    }
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM