gpt4 book ai didi

javascript - 如何从嵌套的 JSON 数据中获取值

转载 作者:行者123 更新时间:2023-12-03 00:09:56 25 4
gpt4 key购买 nike

我正在尝试从下面的嵌套 JSON 数据中获取值。具体来说,付款捕获的 id 值 0TA12948FV40723B 是我需要的值。

我尝试使用以下代码来检索该值。

details.purchase_units.payments.captures.id

details.purchase_units.payments[0].captures.id

但我不断收到 console.log 错误:“无法捕获订单”

JSON 数据

{
"create_time":"2019-02-19T05:06:52Z",
"update_time":"2019-02-19T05:06:52Z",
"id":"3HB96413YD922272B",
"intent":"CAPTURE",
"status":"COMPLETED",
"payer":{
"email_address":"a@yandex.com",
"payer_id":"WEJUPTK4U53E9",
"address":{
"address_line_1":"1 Main St",
"admin_area_2":"San Jose",
"admin_area_1":"CA",
"postal_code":"95131",
"country_code":"US"
},
"name":{
"given_name":"a",
"surname":"som"
},
"phone":{
"phone_number":{
"national_number":"408-214-8270"
}
}
},
"purchase_units":[{
"reference_id":"default",
"amount":{
"value":"1.01",
"currency_code":"USD"
},
"payee":{
"email_address":"gr-facilitator@yandex.com",
"merchant_id":"MSOIGVMKKWAMA"
},
"shipping":{
"name":{
"full_name":"Mr T"
},
"address":{
"address_line_1":"1234 Main St.",
"address_line_2":"Unit 1",
"admin_area_2":"Chicago",
"admin_area_1":"IL",
"postal_code":"60652","country_code":"US"
}
},
"payments":{
"captures":[{
"status":"COMPLETED",
"id":"0TA12948FV40723B",
"final_capture":true,
"create_time":"2019-02-20T05:06:52Z",
"update_time":"2019-02-20T05:06:52Z",
"amount":{
"value":"1.01","currency_code":"USD"
},
"seller_protection":{
"status":"ELIGIBLE",
"dispute_categories":[
"ITEM_NOT_RECEIVED",
"UNAUTHORIZED_TRANSACTION"
]}
}
]}
}]
}

最佳答案

由于purchase_unitscaptures是数组:

details.purchase_units[0].payments.captures[0].id

关于javascript - 如何从嵌套的 JSON 数据中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54785485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com