typescript 从JSON获取过滤器特定的“集合”

pftdvrlh  于 2023-03-31  发布在  TypeScript
关注(0)|答案(1)|浏览(136)

例如,这将是输出,但这个JSON响应将更长,我只想从这个响应中过滤出具有特定合同地址(集合)的NFT。
在React中使用axios和typescript。

{
  "ownedNfts": [
    {
      "contract": {
        "address": "0x3e7b38e7f6c089345ccca785b18890c528636673"
      },
      "id": {
        "tokenId": "0x0000000000000000000000000000000000000000000000000000000000000ab5",
        "tokenMetadata": {
          "tokenType": "ERC721"
        }
      },
      "balance": "1",
      "title": "The Beginning / 01",
      "description": "Every plan starts with an idea - the conception of something new. This is the beginning.",
      "tokenUri": {
        "gateway": "https://ipfs.io/ipfs/QmXuj8hoJgGngkUfBgNUggzCVbZVNFfgyi5WvZuiSuK7aJ/2741",
        "raw": "ipfs://QmXuj8hoJgGngkUfBgNUggzCVbZVNFfgyi5WvZuiSuK7aJ/2741"
      },
      "media": [
        {
          "gateway": "https://nft-cdn.alchemy.com/eth-mainnet/533ed4162c1fb0809092e309790b9b2b",
          "thumbnail": "https://res.cloudinary.com/alchemyapi/image/upload/thumbnailv2/eth-mainnet/533ed4162c1fb0809092e309790b9b2b",
          "raw": "ipfs://QmZMjHkzomQrYPWTTtBSrV3otynxLzybnrrFgo4HJHc5Tm/send-it.MP4",
          "format": "mp4",
          "bytes": 638290
        }
      ],
      "metadata": {
        "name": "The Beginning / 01",
        "description": "Every plan starts with an idea - the conception of something new. This is the beginning.",
        "image": "ipfs://QmZMjHkzomQrYPWTTtBSrV3otynxLzybnrrFgo4HJHc5Tm/send-it.MP4",
        "attributes": []
      },
      }
    },
wswtfjt7

wswtfjt71#

const filtered = json.ownedNfts.filter(
  nft => nft.contract.address === "the address I'm looking for"
)

相关问题