I have excel sheet which i need to build the json file. i have build a sample file. but i am unable to proceed with that json file and extract the data from it.
[{
"Material thickness": "10 Mil",
"Width": 8,
"height": 8,
"Price": "8.76",
"Quantity":1
},
{
"Material thickness": "7 Mil",
"Width": 8,
"height": 12,
"Price": "10.52",
"Quantity":1
}
]
jQuery.getJSON( siteURL+"/prices.json", function( data ) {
jQuery.each(data, function (index, value) {
console.log(index);
console.log(value);
console.log(data[index].Material thickness);
});
});
You can't use the dot
notation when your key contains a space.
The property accessed with a dot notation must be a sequence of alphanumerical characters, also including the underscore ("_") and dollar sign ("$"), that cannot start with a number
Use the bracket
notation instead :
data[index]['Material thickness']
var data = [{ "Material thickness": "10 Mil", "Width": 8, "height": 8, "Price": "8.76", "Quantity": 1 }, { "Material thickness": "7 Mil", "Width": 8, "height": 12, "Price": "10.52", "Quantity": 1 } ]; $.each(data, function(index, value) { //console.log(index); //console.log(value); console.log(data[index]['Material thickness']); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
您可以使用以下内容:
console.log(data[index]["Material thickness"]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.