使用属性解析Json响应

时间:2018-05-22 15:50:37

标签: php jquery json ajax

我试图解析下面来自Ajax响应的Json结果。 Foreach CostingItem我需要访问UnitPrice.Amount,但是我收到了错误。

有人可以帮我查看物品吗?

我从基于Laravle的webservice得到了这个回复。

{
    "CostingItem": [{
        "@attributes": {
            "Description": "Basic Price",
            "Quantity": "1",
            "PassengerRPH": "1",
            "PriceBasis": "Passenger"
        },
        "UnitPrice": {
            "@attributes": {
                "Amount": "1823.82",
                "OriginalAmount": "1974.32"
            }
        },
        "ExtendedPrice": {
            "@attributes": {
                "Amount": "1823.82",
                "OriginalAmount": "1974.32"
            }
        },
        "Commission": {
            "@attributes": {
                "Rate": "11.00",
                "Type": "P"
            }
        }
    }, {
        "@attributes": {
            "Description": "Basic Price",
            "Quantity": "1",
            "PassengerRPH": "2",
            "PriceBasis": "Passenger"
        },
        "UnitPrice": {
            "@attributes": {
                "Amount": "1823.82",
                "OriginalAmount": "1974.32"
            }
        },
        "ExtendedPrice": {
            "@attributes": {
                "Amount": "1823.82",
                "OriginalAmount": "1974.32"
            }
        },
        "Commission": {
            "@attributes": {
                "Rate": "11.00",
                "Type": "P"
            }
        }
    }]
}
  

这是Ajax中使用的脚本:

$.ajax({
    type: "POST",
    url: "/public/fetch-bambini",
    data: {
        id: d,
        tipologia: tipologia,
        bambini: bambini,
        neonati: neonati,
        adulti: adulti
    },
    success: function(response) {
        $.each(response.CostingItem, function(k, v) {
            console.log(v);
        });
    }
});

返回此回复:

enter image description here

0 个答案:

没有答案