je le flux JSON suivant:jQuery - Extrait de données JSON
{"mouldings":[{"moulding_id_2":{"cost":"3.1","width":45}},{"moulding_id_4":{"cost":"1.5","width":30}},{"moulding_id_6":{"cost":"2.1","width":50}}],"material_costs":[{"mountboard":{"cost":"0.00000246494303242769"}},{"glass":{"cost":"0.0000032426589803639"}},{"backing_board":{"cost":"0.00000135110790848496"}}],"app_options":[{"vat":{"value":"17.5"}},{"wastage":{"value":"20"}},{"markup":{"value":"3"}}]}
Je suis en train d'extraire le coût d'un moulage particulier en utilisant jQuery .getJSON. Mon code jQuery est la suivante:
$.getJSON('/calculate_quote/2,6,4.json', function (data) {
alert(data.mouldings.moulding_id_2.cost);
});
Lorsque cela fonctionne, je reçois l'erreur suivante:
Uncaught TypeError: Cannot read property 'cost' of undefined
Pourquoi ai-je cette erreur, merci beaucoup.