Reputation: 2216
I have a json sample menulist.json
(attached in pastebin) that needs to be read in jsavascript. I'm reading file as mentioned in this answer.
But looks like JavaScript is not reading JSON properly.
Beverages
and Desserts
should be under Menu
. But it doesn't seem to be happening:
Just to verify same json, I pasted that in python shell. It looks like python is reading properly.
Here is my code: HTML
<html>
<head>
...
...
...
<script type="text/javascript" src="menulist.json"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</head>
<body>
...
...
...
</body>
</html
Note : It's not about the ordering or sequence. It's about the child objects not appearing under same key.
Upvotes: 0
Views: 65
Reputation: 60143
(transferring comment to answer)
The JavaScript in the Pastebin defines an object with the structure you're expecting, so that must not be the JavaScript you're actually executing. Per the comment discussion above, it turned out that the browser was caching an old version of the file (when the object apparently had a different structure).
Upvotes: 1