我想循环json数据但选择产品,困难在于我要选择的对象遵循模式product-*。我想找到一种允许以下内容的代码和平:
$.each(data.products, function(i, product) {
console.log(product.products_name);
});
实际数据 JSON 是:
{
"orders_id": "411",
"customers_name": "Larez",
"product-1": {
"product_name": "Walt",
"product_type": "Poster",
"product_quantity": "100",
"product_size": "1/4 Pliego",
"product_price": "100.00"
},
"product-2": {
"product_name": "Penny",
"product_type": "Poster",
"product_quantity": "15",
"product_size": "1/4 Pliego",
"product_price": "15.00"
},
"product-3": {
"product_name": "Carol",
"product_type": "Poster",
"product_quantity": "50",
"product_size": "1/4 Pliego",
"product_price": "50.00"
},
"product-4": {
"product_name": "Julia",
"product_type": "Poster",
"product_quantity": "100",
"product_size": "1/4 Pliego",
"product_price": "100.00"
}
}