我有一個 JSON 格式的 String 欄位,我試圖從中提取條紋拒絕代碼。該欄位的示例如下:
{"errors":[{"message":"Your card has insufficient funds.","type":"payment","code":"card_declined","decline_code":"insufficient_funds","gateway":"stripe","stripe":{"type":"card_error","code":"card_declined","decline_code":"insufficient_funds","message":"Your card has insufficient funds.","charge":"ch_3JodUAHkqql8g8ta1ADf5fBf"}}]}
我嘗試了各種組合,UNNEST但仍然收到錯誤訊息。我認為這個問題與該領域是各種結構/陣列的組合有關,但沒有運氣提取我需要的東西。任何幫助將不勝感激!
uj5u.com熱心網友回復:
我想我找到了解決辦法。有點 hacky,但我在 CTE 中做了以下操作;
REPLACE(REPLACE(JSON_EXTRACT(error_message, '$.errors'),"[",""),"]","") as struct_1
然后再取一個 JSON_EXTRACT ;
JSON_EXTRACT(struct_1,'$.stripe.decline_code')
uj5u.com熱心網友回復:
考慮以下方法 - 非hacky :o)
select json_extract_scalar(error, '$.stripe.decline_code') as decline_code
from your_table,
unnest(json_extract_array(error_message, '$.errors')) error
如果應用于您問題中的樣本資料 - 輸出是

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/365824.html
