Hi guys, I wanted to know if it´s possible to save data like: (order: int, player: string, score: int) on a JSON file and also to retrieve that information later on. I know little or nothing about JSON, is it possible to retrieve data with javascript? or do I have to use AJAX?
Thanks for reading!
JSON Database
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: JSON Database
MongoDB is essentially a JSON database, although there is a bit more to it than that. It cuts out a lot of the complexity to building, maintaining and querying a relational database such as MySQL.
As far as using JSON data in your applications, you can most definitely get the data with Javascript. That is the easiest language to work with JSON, since JSON is a subset of JS. You can use these methods to work with it:
To turn a JS object into a JSON string:
And to turn it back into a Javascript object from the JSON string:
You can do that with AJAX, just in your own scripts, or wherever.
As far as using JSON data in your applications, you can most definitely get the data with Javascript. That is the easiest language to work with JSON, since JSON is a subset of JS. You can use these methods to work with it:
To turn a JS object into a JSON string:
Code: Select all
var jsonString = JSON.stringify(jsObj);Code: Select all
var jsObject = JSON.parse(jsonString);The indelible lord of tl;dr
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: JSON Database
Oh, I forgot to mention that the JSON global object used to deal with JSON is part of ECMAscript 5, and thus, is not available in older browsers. For compatibility, Douglas Crockford created a script that adds a JSON global object in browsers that don't already have it. Include the json2.js script on your page, then you can use the global JSON object anywhere.
The indelible lord of tl;dr