使用jQuery

时间:2019-07-05 14:08:48

标签: jquery json

我正在尝试使用jQuery从JSON变量中检索一些数据。这是变量内的JSON:

var jsonContent = [{"attributes":{"Size":"0"},"optionValues":[{"optionName":"Size","value":"0"}],"id":"ce3d72cb-2338-45e1-b2d7-bb8c2161aec4","sku":"SQ0788702","price":75000,"salePrice":0,"priceMoney":{"currency":"GBP","value":"750.00"},"salePriceMoney":{"currency":"GBP","value":"0.00"},"onSale":false,"unlimited":false,"qtyInStock":0,"width":0.0,"height":0.0,"weight":0.0,"imageIds":[],"images":[],"len":0.0},{"attributes":{"Size":"1"},"optionValues":[{"optionName":"Size","value":"1"}],"id":"1f8defcf-e24f-4872-8915-f97e57e9e1b4","sku":"SQ6572698","price":75000,"salePrice":0,"priceMoney":{"currency":"GBP","value":"750.00"},"salePriceMoney":{"currency":"GBP","value":"0.00"},"onSale":false,"unlimited":false,"qtyInStock":1,"width":0.0,"height":0.0,"weight":0.0,"imageIds":[],"images":[],"len":0.0},{"attributes":{"Size":"2"},"optionValues":[{"optionName":"Size","value":"2"}],"id":"33dca3a3-d7b7-4f2a-9cd1-8427f3bcc494","sku":"SQ8872334","price":75000,"salePrice":0,"priceMoney":{"currency":"GBP","value":"750.00"},"salePriceMoney":{"currency":"GBP","value":"0.00"},"onSale":false,"unlimited":false,"qtyInStock":3,"width":0.0,"height":0.0,"weight":0.0,"imageIds":[],"images":[],"len":0.0},{"attributes":{"Size":"3"},"optionValues":[{"optionName":"Size","value":"3"}],"id":"014b0cd9-49a3-4106-a0d0-eab1f8bb761e","sku":"SQ0092817","price":75000,"salePrice":0,"priceMoney":{"currency":"GBP","value":"750.00"},"salePriceMoney":{"currency":"GBP","value":"0.00"},"onSale":false,"unlimited":false,"qtyInStock":0,"width":0.0,"height":0.0,"weight":0.0,"imageIds":[],"images":[],"len":0.0},{"attributes":{"Size":"4"},"optionValues":[{"optionName":"Size","value":"4"}],"id":"21ded538-5324-4253-8644-36c09d9988d9","sku":"SQ9324688","price":75000,"salePrice":0,"priceMoney":{"currency":"GBP","value":"750.00"},"salePriceMoney":{"currency":"GBP","value":"0.00"},"onSale":false,"unlimited":false,"qtyInStock":0,"width":0.0,"height":0.0,"weight":0.0,"imageIds":[],"images":[],"len":0.0},{"attributes":{"Size":"5"},"optionValues":[{"optionName":"Size","value":"5"}],"id":"61a57e43-26c7-47d8-b443-a941e9bd7d61","sku":"SQ7738181","price":75000,"salePrice":0,"priceMoney":{"currency":"GBP","value":"750.00"},"salePriceMoney":{"currency":"GBP","value":"0.00"},"onSale":false,"unlimited":false,"qtyInStock":0,"width":0.0,"height":0.0,"weight":0.0,"imageIds":[],"images":[],"len":0.0},{"attributes":{"Size":"6"},"optionValues":[{"optionName":"Size","value":"6"}],"id":"59c03910-b050-4077-9b65-43ac09a15091","sku":"SQ8852872","price":75000,"salePrice":0,"priceMoney":{"currency":"GBP","value":"750.00"},"salePriceMoney":{"currency":"GBP","value":"0.00"},"onSale":false,"unlimited":false,"qtyInStock":0,"width":0.0,"height":0.0,"weight":0.0,"imageIds":[],"images":[],"len":0.0}];

jsonContent = JSON.stringify(jsonContent);
jsonContent = JSON.parse(jsonContent);

我正在尝试使用此方法检索数据:

$.each(JSON.jsonContent, function(i, object) {
    $.each(object, function(property, value) {
        alert(attributes.size + "=" + value);
    });
});

0 个答案:

没有答案