首页 > 解决方案 > 从对象数组访问 JSON 数据,然后从数组中的对象访问

问题描述

我有以下 JSON 数据。这是一个包含两个对象的数组。

第一个对象(“accounts”)是一个对象数组。我试图访问这个数组中的最后一个对象,并进入它的“余额”对象。然后我想访问最终帐户(第二个)并从中提取最终的“可用”。

[{
    "accounts": [{
            "account_id": "test",
            "balances": {
                "available": 3.45,
                "current": 3.45,
                "iso_currency_code": "GBP",
                "limit": null,
                "unofficial_currency_code": null
            },
            "mask": null,
            "name": "test",
            "official_name": null,
            "subtype": "savings",
            "type": "depository"
        },
        {
            "account_id": "test",
            "balances": {
                "available": 1500,
                "current": 1500,
                "iso_currency_code": "GBP",
                "limit": null,
                "unofficial_currency_code": null
            },
            "mask": null,
            "name": "test",
            "official_name": null,
            "subtype": "savings",
            "type": "depository"
        }
    ],
    "item": {
        "available_products": ["balance", "identity"],
        "billed_products": ["auth", "transactions"],
        "consent_expiration_time": "2021-04-20T13:49:20Z",
        "error": null,
        "institution_id": "ins_117243",
        "item_id": "test",
        "webhook": ""
    },
    "request_id": "999",
    "status_code": 200
}]

我想通过映射或点符号来做到这一点。

数据存储在状态内部的 React 前端。

有人可以告诉我如何最好地访问帐户数组中最终余额对象中的可用数据。

这将是“1500”。

标签: javascript

解决方案


推荐阅读