tirsdag den 4. august 2009

Reading JSON Data with Dojo


FYI
/Sik


Learn the moves at the Dojo ...
/Sik


Quote

by epimpler

What is JSON?
JSON or JavaScript Object Notation is a text based, lightweight data-interchange format that is easy for a human to read. In addition, from an application development standpoint it’s easy to write and parse. JSON is typically preferable to XML if you have a choice. Since the format of JSON is close to what you find with JavaScript objects it requires less translation than XML and has been clocked at as much as 100 times faster than XML in a browser environment (Dojo: The Definitive Guide). To see an example JSON file please click here.

ItemFileReadStore
Dojo uses the ItemFileReadStore and ItemFileWriteStore data stores to work with JSON format data. ItemFileReadStore implements the Read and Identity APIs and is used to read JSON data while ItemFileWriteStore is used to write JSON format data and implements all four of the Data APIs. We’ll be discussing ItemFileReadStore in this post.

ItemFileReadStore is the specific data store implementation for reading JSON data. In addition to implementing the Read and Identity APIs, ItemFileReadStore also contains additional implementation features including a specific data format, query syntax, means for deserializing attribute values, identifiers for items, and others. Now let’s look at an example of the data format expected by ItemFileReadStore.

ItemFileReadStore requires that JSON data follow a specific structure which is outlined via a code example shown in the figure below.

The identifier property points to the identifier attribute in items. An optional label property points to the label attribute. Finally, the data itself comes in items, which is an array of attribute/value pairs. The test data shown in the example was taken from a JSON file containing wildfire information. Ultimately each of these wildfires is plotted to our sample Google Maps application as a marker. Each wildfire is given a unique numeric identifier and the label is simply the latitude and longitude coordinates combined. The items are a collection of attribute/value pairs listing information about the specific fire including the coordinates, date, time, satellite that identified the fire, and the confidence value. [...]


Read more: http://geochalkboard.wordpress.com/2009/08/03/reading-json-data-with-dojo/

Ingen kommentarer:

Send en kommentar