I am very new to JSON and this forum, hope someone can help.
In a HTML file I have the following javascript:
<script type="text/javascript" src="ExternalData.json"></script> and
var mydata = JSON.parse(data); alert(mydata.length); var div = document.getElementById('data'); alert(mydata[0].name); alert(mydata[1].name); alert(mydata[0].age); alert(mydata[1].age); In a separate ExternalData.json file I have:
data = '[{"name" : "Bob", "age" : "2"},{"name" : "Mary", "age" : "4"}]'; Everything works fine, however when I try to add return marks to the JSON file like this:
data = '[ {"name" : "Bob", "age" : "2"}, {"name" : "Mary", "age" : "4"}]'; It no longer works for me.
What have I missed? Something basic but I have no idea!
This will eventually be a large amount of data that will be updated by a colleague unfamiliar with coding. Having all the information on one line is not workable.