我想獲得redirectUrl價值。所以我寫這樣的代碼。我覺得太復雜了??赡苡衅渌椒梢缘玫絾??var v interface{}req.ToJSON(&v)a := v.(map[string]interface{})b := a["browserPayment"].(map[string]interface{})logs.Info(b["redirectUrl"])這是回應:{"browserPayment":{"interaction":{"status":"INITIATED","timeInitiated":"xxxxxx"},"operation":"PAY","redirectUrl":"xxxxx","returnUrl":"http://localhost"},"gatewayEntryPoint":"xxxxx","merchant":"xxxxx","order":{"amount":1,"chargeback":{"amount":0,"currency":"USD"},"creationTime":"xxxxxx","currency":"USD","id":"xxxxxx","merchantAmount":1,"merchantCurrency":"USD","status":"INITIATED","totalAuthorizedAmount":0,"totalCapturedAmount":0,"totalRefundedAmount":0},"response":{"gatewayCode":"SUBMITTED"},"result":"SUCCESS","sourceOfFunds":{"type":"UNION_PAY"},"timeOfRecord":"xxxxxxx","transaction":{"acquirer":{"id":"xxxxxxx","merchantId":"xxxxx"},"amount":1,"currency":"USD","id":"xxxxx","source":"INTERNET","type":"PAYMENT"},"version":"56"}
1 回答

鴻蒙傳說
TA貢獻1865條經驗 獲得超7個贊
聲明一個類型與數據結構匹配的變量。解組該值:
var v struct { BrowserPayment struct { RedirectUrl string }}
req.ToJSON(&v)
logs.Info(v.BrowserPayment.RedirectUrl)
建議:檢查并處理ToJSON返回的錯誤。
- 1 回答
- 0 關注
- 137 瀏覽
添加回答
舉報
0/150
提交
取消