【问题标题】:Access deep json link for redirect访问深度 json 链接以进行重定向
【发布时间】:2013-09-12 03:35:13
【问题描述】:

我在 PayPal for HATEOS 上有以下示例。我想访问该链接,但是在我的浏览器上遇到了有关语法错误的问题。

SyntaxError: missing ) after argument list [Break On This Error]

警报(links.1.href);

(第 32 行,第 15 列)

JSON 来自我正在尝试访问链接的贝宝

{
    "id": "PAY-23P72370PE379301LKIWIOTQ",
    "create_time": "2013-09-08T14:18:54Z",
    "update_time": "2013-09-08T14:18:54Z",
    "state": "created",
    "intent": "sale",
    "payer": {
        "payment_method": "paypal"
    },
    "transactions": [
        {
            "amount": {
                "total": "7.47",
                "currency": "USD",
                "details": {
                    "subtotal": "7.47"
                }
            },
            "description": "payment using a PayPal account"
        }
    ],
    "links": [
        {
            "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-23P72370PE379301LKIWIOTQ",
            "rel": "self",
            "method": "GET"
        },
        {
            "href": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-8DG907196F781211F",
            "rel": "approval_url",
            "method": "REDIRECT"
        },
        {
            "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-23P72370PE379301LKIWIOTQ/execute",
            "rel": "execute",
            "method": "POST"
        }
    ]
}

如何访问 REDIRECT 的链接?

alert(links.1.href);

谢谢

【问题讨论】:

    标签: javascript jquery json paypal


    【解决方案1】:

    要访问数组元素,您应该使用以下语法:

    alert(links[1].href);
    

    这里的工作示例:http://jsfiddle.net/skghW/

    【讨论】:

      【解决方案2】:

      找到了!

      警报(data.links[1].href);

      谢谢

      【讨论】:

        猜你喜欢
        • 2021-03-24
        • 2020-07-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多