As a newcomer to JSON, I wanted my webpage to display a small database of records in a table without using a traditional database like MySQL. Instead, I decided to read data from and write it out to a JSON file for convenient and persistent storage on my website.
I spent some time creating a script that converted my existing papers file into a "papers.json" file containing all the records, which looks like this:
[
{"title" : "IEEE Standard for Local and Metropolitan Area Networks: Overview and Architecture",
"authors" : "IEEE",
"pub" : "IEEE 802-2001 standard",
"datepub" : "2001",
"keywords" : "MAC",
"dateread" : "200309",
"physloc" : "box i",
"comment" : "Indicates how you can manage addresses assigned to you by IEEE."
},
{"title" : "A framework for delivering multicast messages in networks with mobile hosts",
"authors" : "A. Acharya, B. R. Badrinath",
"pub" : "Mobile Networks and Applications v1 pp 199-219",
"datepub" : "1996",
"keywords" : "multicast mobile MH MSS",
"dateread" : "",
"physloc" : "box a",
"comment" : ""
},
<hundreds more similar papers records here...>
},
{"title" : "PiOS: detecting privacy leaks in iOS applications",
"authors" : "M. Egele, C. Kruegel, E. Kirda, G. Vigna",
"pub" : "NDSS 2011",
"datepub" : "2011",
"keywords" : "iOS app location leakage",
"dateread" : "",
"physloc" : "box e",
"comment" : "discussed at Latte"
}
]
Below is the JavaScript code I'm using to read the JSON file. (I haven't implemented writing the records yet because the reading process isn't functioning properly.)
var pdb = []; // global
var doneReading = false; //global
$(document).ready(function() {
$.getJSON('papers.json',function(data) {
pdb = data;
doneReading = true;
});
while (!doneReading) {}
alert("finished assignment of JSON to pdb"+" "+typeof pdb);
//alert(pdb[0].title);
console.log(pdb[2]);
//setup();
});
The issue arises as the script gets stuck in an endless loop. Why does this happen?
Additionally, since I'm new to jQuery, I wonder if it's possible to manipulate JSON files without using jQuery, as I prefer mastering one concept at a time without relying on libraries.