我正在尝试从下面的嵌套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"
]}
}
]}
}]
}
答案 0 :(得分:1)
由于 purchase_units 和 captures 是数组:
details.purchase_units[0].payments.captures[0].id
答案 1 :(得分:0)
captures键在数组中具有对象。因此您不能像
那样简单地获取details.purchase_units.payments[0].captures.id
您必须给出捕获位置或循环数组,只有您可以进行解析
details.purchase_units.payments[0].captures[0].id
答案 2 :(得分:0)
答案 3 :(得分:0)
如果要捕获阵列中的所有ID,可以使用通配符:
details.purchase_units[*].payments.captures[*].id
这将解析指定路径的完整有效负载并收集数组中的所有ID。