0

我有一个这样的字符串。

    {
  "type": "item",
  "version": "3.10.3",
  "basic": {
    "name": "",
    "rune": {
      "isrune": false,
      "tier": 1,
      "type": "red"
    },
    "gold": {
      "base": 0,
      "total": 0,
      "sell": 0,
      "purchasable": false
    },
    "group": "",
    "description": "",
    "colloq": ";",
    "plaintext": "",
    "consumeable": false,
    "stacks": 1,
    "depth": 1,
    "consumed": false,
    "consumeOnFull": false,
    "from": [],
    "into": [],
    "specialRecipe": 0,
    "inStore": true,
    "hideFromAll": false,
    "requiredChampion": "",
    "stats": {
      "FlatHPPoolMod": 0,
      "rFlatHPModPerLevel": 0,
      "FlatMPPoolMod": 0,
      "rFlatMPModPerLevel": 0,
      "PercentHPPoolMod": 0,
      "PercentMPPoolMod": 0,
      "FlatHPRegenMod": 0,
      "rFlatHPRegenModPerLevel": 0,
      "PercentHPRegenMod": 0,
      "FlatMPRegenMod": 0,
      "rFlatMPRegenModPerLevel": 0,
      "PercentMPRegenMod": 0,
      "FlatArmorMod": 0,
      "rFlatArmorModPerLevel": 0,
      "PercentArmorMod": 0,
      "rFlatArmorPenetrationMod": 0,
      "rFlatArmorPenetrationModPerLevel": 0,
      "rPercentArmorPenetrationMod": 0,
      "rPercentArmorPenetrationModPerLevel": 0,
      "FlatPhysicalDamageMod": 0,
      "rFlatPhysicalDamageModPerLevel": 0,
      "PercentPhysicalDamageMod": 0,
      "FlatMagicDamageMod": 0,
      "rFlatMagicDamageModPerLevel": 0,
      "PercentMagicDamageMod": 0,
      "FlatMovementSpeedMod": 0,
      "rFlatMovementSpeedModPerLevel": 0,
      "PercentMovementSpeedMod": 0,
      "rPercentMovementSpeedModPerLevel": 0,
      "FlatAttackSpeedMod": 0,
      "PercentAttackSpeedMod": 0,
      "rPercentAttackSpeedModPerLevel": 0,
      "rFlatDodgeMod": 0,
      "rFlatDodgeModPerLevel": 0,
      "PercentDodgeMod": 0,
      "FlatCritChanceMod": 0,
      "rFlatCritChanceModPerLevel": 0,
      "PercentCritChanceMod": 0,
      "FlatCritDamageMod": 0,
      "rFlatCritDamageModPerLevel": 0,
      "PercentCritDamageMod": 0,
      "FlatBlockMod": 0,
      "PercentBlockMod": 0,
      "FlatSpellBlockMod": 0,
      "rFlatSpellBlockModPerLevel": 0,
      "PercentSpellBlockMod": 0,
      "FlatEXPBonus": 0,
      "PercentEXPBonus": 0,
      "rPercentCooldownMod": 0,
      "rPercentCooldownModPerLevel": 0,
      "rFlatTimeDeadMod": 0,
      "rFlatTimeDeadModPerLevel": 0,
      "rPercentTimeDeadMod": 0,
      "rPercentTimeDeadModPerLevel": 0,
      "rFlatGoldPer10Mod": 0,
      "rFlatMagicPenetrationMod": 0,
      "rFlatMagicPenetrationModPerLevel": 0,
      "rPercentMagicPenetrationMod": 0,
      "rPercentMagicPenetrationModPerLevel": 0
    },
    "tags": [],
    "maps": {
      "1": true,
      "8": true,
      "10": true,
      "12": true
    }
  },
  "data": {
    "1001": {
      "name": "Boots of Speed",
      "group": "BootsNormal",
      "description": "<groupLimit>Limited to 1.</groupLimit><br><br><unique>UNIQUE Passive - Enhanced Movement:</unique> +25 Movement Speed<br><br><i>(Unique Passives with the same name don't stack.)</i>",
      "colloq": ";",
      "plaintext": "Slightly increases Movement Speed",
      "into": [
        "3006",
        "3047",
        "3020",
        "3158",
        "3111",
        "3117",
        "3009"
      ],
      "image": {
        "full": "1001.png",
        "sprite": "item0.png",
        "group": "item",
        "x": 0,
        "y": 0,
        "w": 48,
        "h": 48
      },
      "gold": {
        "base": 325,
        "purchasable": true,
        "total": 325,
        "sell": 227
      },
      "tags": [
        "MOVEMENT",
        "BOOTS"
      ],
      "stats": {
        "FlatMovementSpeedMod": 25
      }
    },
    "1004": {
      "name": "Faerie Charm",
      "description": "<stats>+3 Mana Regen per 5 seconds</stats>",
      "colloq": ";",
      "plaintext": "Slightly increases Mana Regen",
      "into": [
        "3037",
        "3096",
        "3028",
        "3070",
        "3073",
        "1080",
        "3165"
      ],
      "image": {
        "full": "1004.png",
        "sprite": "item0.png",
        "group": "item",
        "x": 48,
        "y": 0,
        "w": 48,
        "h": 48
      },
      "gold": {
        "base": 180,
        "purchasable": true,
        "total": 180,
        "sell": 126
      },
      "tags": [
        "MANAREGEN"
      ],
      "stats": {
        "FlatMPRegenMod": 0.6
      }
    },
    "1006": {

它是这样的,我试图从“1006:{但我不能

$iveri =      $iresponse->body;
    foreach($iveri->data as $esya)
            {
            print($esya);

            }

因为它是对象,但我想要它的名字,但我找不到一种方法来获得你能帮助我的方法,我正在构建数据库,就像获取值一样,它们将是它们的 ID,它们是项目的 ID,所以它们不能是自动的评估他们必须像数组一样。

4

1 回答 1

0

1006在您的示例中是一个键值,您需要稍微修改循环语法:

foreach($ivery->data as $key=>$esya) {
  print $key; // This will be '1006'
  print $esya;
}
于 2013-08-13T14:22:02.897 回答