为了账号安全,请及时绑定邮箱和手机立即绑定

如何简化获取结果表单json

如何简化获取结果表单json

Go
aluckdog 2022-06-13 15:20:32
我想获得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返回的错误。


查看完整回答
反对 回复 2022-06-13
  • 1 回答
  • 0 关注
  • 117 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信