gpt4 book ai didi

json - 如何简化获取结果表单json

转载 作者:行者123 更新时间:2023-12-01 22:12:43 26 4
gpt4 key购买 nike

我想得到redirectUrl值(value)。所以我写这样的代码。我觉得太复杂了。可能有其他方法可以得到吗?

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"}

最佳答案

声明一个类型与数据结构匹配的变量。解码该值:

 var v struct { BrowserPayment struct { RedirectUrl string }}
req.ToJSON(&v)
logs.Info(v.BrowserPayment.RedirectUrl)
建议:检查并处理ToJSON返回的错误。

关于json - 如何简化获取结果表单json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62547111/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com