0

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);                             
  });                           
}); 

2 Answers 2

1

You can use the following:

console.log(data[index]["Material thickness"]);
Sign up to request clarification or add additional context in comments.

Comments

1

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>

1 Comment

getting error { "message": "Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode", "filename": "stacksnippets.net/js", "lineno": 13, "colno": 9 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.