首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从JSON响应中获取数据

如何从JSON响应中获取数据
EN

Stack Overflow用户
提问于 2022-08-01 22:25:24
回答 1查看 27关注 0票数 0

例如,我试图从这种类型的JSON中获得_id

代码语言:javascript
复制
[
    {
        "_id": 7,
        "baalut": "פרטי",
        "degem_cd": 558,
        "degem_manoa": "CVK",
        "degem_nm": "B8-8W2CDG",
        "horaat_rishum": 160046,
        "kinuy_mishari": "A4",
        "kvutzat_zihum": 7,
        "misgeret": "WAUZZZF46GA038023",
        "mispar_rechev": 2623638,
        "mivchan_acharon_dt": "2021-04-14T00:00:00",
        "moed_aliya_lakvish": "2016-3",
        "ramat_eivzur_betihuty": 1,
        "ramat_gimur": "LUXURY DSN",
        "rank": 0.0573088,
        "shnat_yitzur": 2016,
        "sug_degem": "P",
        "sug_delek_nm": "בנזין",
        "tokef_dt": "2022-03-08T00:00:00",
        "tozeret_cd": 19,
        "tozeret_nm": "אאודי",
        "tzeva_cd": 80,
        "tzeva_rechev": "שנהב לבן",
        "zmig_ahori": "245/35 R19",
        "zmig_kidmi": "245/35 R19"
    }
]

总的来说,这个JSON响应很长,所以我将删除不必要的响应。这是我的密码:

代码语言:javascript
复制
const json = await response.json();
console.log(json.result.records);

我得到了前面显示的结果,但是现在我想在JSON中获取数据,所以我尝试执行json.result.records._id,但它显示了undefined

我是json.result

代码语言:javascript
复制
{
    "_links": {
        "next": "/api/3/action/datastore_search?resource_id=053cea08-09bc-40ec-8f7a-156f0677aff3&q=2623638&limit=1&offset=1",
        "start": "/api/3/action/datastore_search?resource_id=053cea08-09bc-40ec-8f7a-156f0677aff3&q=2623638&limit=1"
    },
    "fields": [
        {
            "id": "_id",
            "type": "int"
        },
        {
            "id": "mispar_rechev",
            "info": [Object
            ],
            "type": "numeric"
        },
        {
            "id": "tozeret_cd",
            "info": [Object
            ],
            "type": "numeric"
        },
        {
            "id": "sug_degem",
            "info": [Object
            ],
            "type": "text"
        },
        {
            "id": "tozeret_nm",
            "info": [Object
            ],
            "type": "text"
        },
        {
            "id": "degem_cd",
            "info": [Object
            ],
            "type": "numeric"
        },
        {
            "id": "degem_nm",
            "info": [Object
            ],
            "type": "text"
        },
        {
            "id": "ramat_gimur",
            "info": [Object
            ],
            "type": "text"
        },
        {
            "id": "ramat_eivzur_betihuty",
            "info": [Object
            ],
            "type": "numeric"
        },
        {
            "id": "kvutzat_zihum",
            "info": [Object
            ],
            "type": "numeric"
        },
        {
            "id": "shnat_yitzur",
            "info": [Object
            ],
            "type": "numeric"
        },
        {
            "id": "degem_manoa",
            "info": [Object
            ],
            "type": "text"
        },
        {
            "id": "mivchan_acharon_dt",
            "info": [Object
            ],
            "type": "timestamp"
        },
        {
            "id": "tokef_dt",
            "info": [Object
            ],
            "type": "timestamp"
        },
        {
            "id": "baalut",
            "info": [Object
            ],
            "type": "text"
        },
        {
            "id": "misgeret",
            "info": [Object
            ],
            "type": "text"
        },
        {
            "id": "tzeva_cd",
            "info": [Object
            ],
            "type": "numeric"
        },
        {
            "id": "tzeva_rechev",
            "info": [Object
            ],
            "type": "text"
        },
        {
            "id": "zmig_kidmi",
            "info": [Object
            ],
            "type": "text"
        },
        {
            "id": "zmig_ahori",
            "info": [Object
            ],
            "type": "text"
        },
        {
            "id": "sug_delek_nm",
            "info": [Object
            ],
            "type": "text"
        },
        {
            "id": "horaat_rishum",
            "info": [Object
            ],
            "type": "numeric"
        },
        {
            "id": "moed_aliya_lakvish",
            "info": [Object
            ],
            "type": "text"
        },
        {
            "id": "kinuy_mishari",
            "info": [Object
            ],
            "type": "text"
        },
        {
            "id": "rank",
            "type": "float"
        }
    ],
    "include_total": true,
    "limit": 1,
    "q": "2623638",
    "records": [
        {
            "_id": 7,
            "baalut": "פרטי",
            "degem_cd": 558,
            "degem_manoa": "CVK",
            "degem_nm": "B8-8W2CDG",
            "horaat_rishum": 160046,
            "kinuy_mishari": "A4",
            "kvutzat_zihum": 7,
            "misgeret": "WAUZZZF46GA038023",
            "mispar_rechev": 2623638,
            "mivchan_acharon_dt": "2021-04-14T00:00:00",
            "moed_aliya_lakvish": "2016-3",
            "ramat_eivzur_betihuty": 1,
            "ramat_gimur": "LUXURY DSN",
            "rank": 0.0573088,
            "shnat_yitzur": 2016,
            "sug_degem": "P",
            "sug_delek_nm": "בנזין",
            "tokef_dt": "2022-03-08T00:00:00",
            "tozeret_cd": 19,
            "tozeret_nm": "אאודי",
            "tzeva_cd": 80,
            "tzeva_rechev": "שנהב לבן",
            "zmig_ahori": "245/35 R19",
            "zmig_kidmi": "245/35 R19"
        }
    ],
    "records_format": "objects",
    "resource_id": "053cea08-09bc-40ec-8f7a-156f0677aff3",
    "total": 1,
    "total_estimation_threshold": null,
    "total_was_estimated": false
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-01 23:10:52

您应该能够执行json.result.records._id,记录是一个数组。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73200170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档