#python #json
#python #json
Вопрос:
Я вызываю некоторый API, который возвращает большой блок API. Мне нужна помощь в определении наиболее эффективного способа фильтрации json. Я только когда-либо взаимодействовал с определенными наборами или полями, но не идентифицировал ни одной пары ключ: значение, а затем находил родительский. Как только я нахожу родительский, я хочу вернуть только родительский блок. Как бы я это сделал? Я также пытаюсь понять, какую логику здесь использовать.
Пример блока ниже. Я хотел бы найти ‘itemtype: 19′, а затем вернуть ’86’, а затем, как только у меня будет ’86’, я смогу получить нужные мне значения из 86. Пример [86][itemDefinition][имя].
},
"86":{
"saleStatus":8,
"failureIndexes":[
3
],
"augments":0,
"vendorItemIndex":86,
"itemHash":1476367343,
"quantity":1,
"costs":[
{
"itemHash":4046539562,
"quantity":10
}
],
"itemDefinition":{
"displayProperties":{
"description":"",
"name":"Sword Ammo Finder",
"icon":"/common/destiny2_content/icons/793bc0219a88f4454e413217628c40f0.png",
"iconSequences":[
{
"frames":[
"/common/destiny2_content/icons/793bc0219a88f4454e413217628c40f0.png"
]
},
{
"frames":[
"/common/destiny2_content/icons/e0d0166080ae8c0630338738ac6cff04.png"
]
}
],
"hasIcon":True
},
"tooltipNotifications":[
],
"collectibleHash":1263137395,
"backgroundColor":{
"colorHash":0,
"red":0,
"green":0,
"blue":0,
"alpha":0
},
"itemTypeDisplayName":"Helmet Armor Mod",
"uiItemDisplayStyle":"ui_display_style_energy_mod",
"itemTypeAndTierDisplayName":"Common Helmet Armor Mod",
"displaySource":"",
"tooltipStyle":"build",
"action":{
"verbName":"Dismantle",
"verbDescription":"",
"isPositive":False,
"requiredCooldownSeconds":0,
"requiredItems":[
],
"progressionRewards":[
],
"actionTypeLabel":"shard",
"rewardSheetHash":0,
"rewardItemHash":0,
"rewardSiteHash":0,
"requiredCooldownHash":0,
"deleteOnAction":True,
"consumeEntireStack":False,
"useOnAcquire":False
},
"inventory":{
"maxStackSize":1,
"bucketTypeHash":2422292810,
"recoveryBucketTypeHash":0,
"tierTypeHash":3340296461,
"isInstanceItem":False,
"nonTransferrableOriginal":False,
"tierTypeName":"Common",
"tierType":2,
"expirationTooltip":"",
"expiredInActivityMessage":"",
"expiredInOrbitMessage":"",
"suppressExpirationWhenObjectivesComplete":True
},
"plug":{
"insertionRules":[
],
"plugCategoryIdentifier":"enhancements.v2_head",
"plugCategoryHash":2912171003,
"onActionRecreateSelf":False,
"actionRewardSiteHash":0,
"actionRewardItemOverrideHash":0,
"insertionMaterialRequirementHash":1564811296,
"previewItemOverrideHash":0,
"enabledMaterialRequirementHash":0,
"enabledRules":[
],
"uiPlugLabel":"",
"plugStyle":0,
"plugAvailability":0,
"alternateUiPlugLabel":"",
"alternatePlugStyle":0,
"isDummyPlug":False,
"energyCost":{
"energyCost":2,
"energyTypeHash":728351493,
"energyType":1
}
},
"acquireRewardSiteHash":0,
"acquireUnlockHash":0,
"investmentStats":[
{
"statTypeHash":3779394102,
"value":2,
"isConditionallyActive":False
}
],
"perks":[
{
"requirementDisplayString":"",
"perkHash":3553498179,
"perkVisibility":0
}
],
"allowActions":True,
"doesPostmasterPullHaveSideEffects":False,
"nonTransferrable":True,
"itemCategoryHashes":[
59,
4104513227,
1362265421
],
"specialItemType":0,
"itemType":19,
"itemSubType":0,
"classType":3,
"breakerType":0,
"equippable":False,
"defaultDamageType":0,
"isWrapper":False,
"hash":1476367343,
"index":8169,
"redacted":False,
"blacklisted":False
}
},
"170":{
"saleStatus":1,
"failureIndexes":[
],
"augments":0,
"vendorItemIndex":170,
"itemHash":2979281381,
"quantity":1,
"costs":[
{
"itemHash":3853748946,
"quantity":1
},
{
"itemHash":1022552290,
"quantity":10
},
{
"itemHash":2014411539,
"quantity":25
},
{
"itemHash":3159615086,
"quantity":5000
}
],
"overrideNextRefreshDate":"2020-09-28T17:00:00Z",
"itemDefinition":{
"displayProperties":{
"description":"A collection of universal components that can be used to infuse power between gear items. Can be purchased from the Gunsmith or acquired from special reward sources.",
"name":"Upgrade Module",
"icon":"/common/destiny2_content/icons/62b016b25d8589f2b15c38890d2b24c3.jpg",
"hasIcon":True
},
"tooltipNotifications":[
],
"backgroundColor":{
"colorHash":0,
"red":94,
"green":12,
"blue":142,
"alpha":255
},
"itemTypeDisplayName":"Material",
"uiItemDisplayStyle":"",
"itemTypeAndTierDisplayName":"Legendary Material",
"displaySource":"",
"action":{
"verbName":"Discard",
"verbDescription":"",
"isPositive":False,
"requiredCooldownSeconds":0,
"requiredItems":[
],
"progressionRewards":[
],
"rewardSheetHash":0,
"rewardItemHash":0,
"rewardSiteHash":0,
"requiredCooldownHash":0,
"deleteOnAction":True,
"consumeEntireStack":False,
"useOnAcquire":False
},
"inventory":{
"stackUniqueLabel":"v460.materials.currencies.infusion_token",
"maxStackSize":25,
"bucketTypeHash":1469714392,
"recoveryBucketTypeHash":215593132,
"tierTypeHash":4008398120,
"isInstanceItem":False,
"nonTransferrableOriginal":False,
"tierTypeName":"Legendary",
"tierType":5,
"expirationTooltip":"",
"expiredInActivityMessage":"",
"expiredInOrbitMessage":"",
"suppressExpirationWhenObjectivesComplete":True
},
"acquireRewardSiteHash":0,
"acquireUnlockHash":0,
"investmentStats":[
],
"perks":[
],
"allowActions":True,
"doesPostmasterPullHaveSideEffects":False,
"nonTransferrable":True,
"itemCategoryHashes":[
40,
52
],
"specialItemType":0,
"itemType":0,
"itemSubType":0,
"classType":3,
"breakerType":0,
"equippable":False,
"defaultDamageType":0,
"isWrapper":False,
"hash":2979281381,
"index":10741,
"redacted":False,
"blacklisted":False
}
},
Комментарии:
1. Вы имеете в виду разбор json вручную и пропуск всего, что вы не ищете, или быстрый просмотр большого словаря?
2. Быстро пройдите по нему, найдите ‘ItemType: 19’, а затем вернитесь назад и найдите родительский элемент, который можно использовать для извлечения любых данных из родительской строки.