如何简化获取结果表单json

我想获得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"}



aluckdog
浏览 118回答 1
1回答

鸿蒙传说

声明一个类型与数据结构匹配的变量。解组该值: var v struct { BrowserPayment struct { RedirectUrl string }} req.ToJSON(&v) logs.Info(v.BrowserPayment.RedirectUrl)建议:检查并处理ToJSON返回的错误。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go