JSON Data Set

Description

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.

File

SpryJSONDataSet.js

Requires

SpryData.js

Inheritance

Notifier -->DataSet --> HTTPSourceDataSet --> JSONDataSet

JSONDataSet constructor

Description

Spry.Data.JSONDataSet is the constructor function for the JSON Data Set.

Format

Spry.Data.JSONDataSet(url, options)

Arguments

Returns

N/A

Example


// 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" ] });

Sample

JSONDataSetSample.html

getDocument

Description

This function returns the JSON string that was used by the data set to extract its data.

Format

getDocument()

Arguments

N/A

Returns

String or null. The JSON string or null;

Example

var jsonStr = ds.geDocument();

getPath

Description

This function returns the path to be used for finding the data to flatten within the JSON data structure.

Format

getPath()

Arguments

N/A

Returns

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.

Example

var path = ds.getPath();

loadDataIntoDataSet

Description

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.

Format

loadDataIntoDataSet(jsonString)

Arguments

jsonString - The raw JSON string that will be eval'd to create the JSON data structure.

Returns

N/A

Example

N/A

setPath

Description

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.

Format

setPath()

Arguments

N/A

Returns

N/A

Example

 ds.setPath("employees.employee");

Copyright © 2007. Adobe Systems Incorporated.
All rights reserved.