0

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

SyntaxError: missing ) 在参数列表 [Break On This Error] 之后

警报(链接.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);

谢谢

4

2 回答 2

1

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

alert(links[1].href);

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

于 2013-09-08T14:28:24.357 回答
0

找到了!

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

谢谢

于 2013-09-08T14:28:21.090 回答