How would that be an improvement over putting the same information in a database table? Should I simply think of JSON as an alternative database (i.e. you can choose between MySQL or JSON)? Or does JSON offer some sort of advantage over a database?
In summary, JSON looks cool, but I haven’t yet grasped exactly what it can do that I’m not already doing with my database.
An ajax call can’t retrieve your database directly - you have to extract the data from the database and then convert the data to a version ajax can read - normally either xml or json.
json is the easiest format for JavaScript to work with because that’s just the simplest way to define objects in native JavaScript.
Wow, I think you answered TWO questions… I’ve started exploring the possibility of using AJAX to display dynamic data. Apparently, it can be done. But I guess JSON would be an alternative way of doing that, too.
Yep, JSON is just the format that the data is sent in with these ajax requests, JSON is a text string representing the object, and besides a couple of edge cases you can convert back and forth.
var object = {
text: 'yep',
number: 123
};
var json = JSON.stringify(object);
console.log(json);
var newObject = JSON.parse(json);
console.log(newObject);
So you JSON.parse the string returned from the server and then can work with the dynamic data in JavaScript.