我一直在试图绕过这个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数组,但这通常是它中断的地方
答案 0 :(得分:0)
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);
}
}
}