The Spry.Data.JSONDataSet class dervies from the HTTPSourceDataSet class so that it can load and process JSON data. The JSONDataSet follows a fixed set of rules for flattening JSON data. If the data to be flattened is not at the top-level of the JSON data structure, a path can be used to identify the data within the JSON structure that should be flattened. You can see how the JSONDataSet flattens various JSON data structures here.
Notifier -->DataSet --> HTTPSourceDataSet --> JSONDataSet
Spry.Data.JSONDataSet is the constructor function for the JSON Data Set.
Spry.Data.JSONDataSet(url, options)
{ "results": { "count": 3, "data": [ { "color": "orange", "category": "sedan" }, { "color": "yellow", "category": "sedan" }, { "color": "red", "category": "coupe" } ] } }
To flatten the structure in the "data" array, you would specify a path of "results.data". Or if you were only interested in extracting out all of the specified "category" values, you could specify a path of "results.data.category".
{ "data": { "firstname": [ "John", "Jane", "Ann" ], "lastname": [ "Smith", "Doe", "Hunt" ] "id": [ "3001", "4532", "5462" ] } }
If the data set was given a path of "data" to flatten, the data set would treat the "data" structure as if it were expressed in this manner:
{ "data": [ { "firstname": "John", "lastname": "Smith", "id": "3001" }, { "firstname": "Jane", "lastname": "Doe", "id": "4532" }, { "firstname": "Ann", "lastname": "Hunt", "id": "5462" } ] }
N/A
// An example of creating a JSON data set that flattens the top-level // structure of the JSON data. var ds = new Spry.Data.JSONDataSet("search.php?id=100"); // An example of creating a JSON data set that uses some DataSet // and HTTPSourceDataSet options. var ds = new Spry.Data.JSONDataSet("search.php?id=100", { useCache: false, loadInterval: 1000 }); // An example of creating a JSON data set that specifies a path // within the JSON data structure to the actual data. var ds = new Spry.Data.JSONDataSet("search.php?id=100", { path: "results.data" }); // An example of creating a JSON data set that specifies a subPath to // include in the flattening process. var ds = new Spry.Data.JSONDataSet("search.php?id=100", { path: "results.employees.employee", subPaths: "reviews.review.date" }); // An example of creating a JSON data set that specifies multiple // subPaths to include in the flattening process. var ds = new Spry.Data.JSONDataSet("search.php?id=100", { path: "results.employees.employee", subPaths: [ "reviews.review.date", "reviews.review.increase" ] });
This function returns the JSON string that was used by the data set to extract its data.
getDocument()
N/A
String or null. The JSON string or null;
var jsonStr = ds.geDocument();
This function returns the path to be used for finding the data to flatten within the JSON data structure.
getPath()
N/A
String or null. Returns the path that will be used to extract the data for flattening out of the JSON data. This may also return a null if no path was specified at construction time.
var path = ds.getPath();
This function is not meant to be called directly. The JSONDataSet overrides the HTTPSourceDataSet version of this function to add the ability to parse and flatten the JSON data.
loadDataIntoDataSet(jsonString)
jsonString - The raw JSON string that will be eval'd to create the JSON data structure.
N/A
N/A
This function sets the path to use to extract data out of the JSON data structure. If the JSON data has already been loaded, the JSONDataSet automatically applies the new object path to re-generate the data for the data set.
setPath()
N/A
N/A
ds.setPath("employees.employee");
Copyright © 2007. Adobe Systems Incorporated.
All rights reserved.