O'Reilly logo

Beginning Adobe® AIR™: Building Applications for the Adobe Integrated Runtime by Rich Tretola

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

7.2. REST

REST stands for Representational State Transfer and is defined as a very simple interface for exchanging data over HTTP without the complexities of web services. SOAP.REST is accessed using either an HTTP get or post, depending on whether you wish to read or write data. Systems that are using REST are often referred to as RESTFul or as a RESTFul data service. The next two examples, using JSON and XML with the Flex <mx:HTTPService> component, illustrate use of a RESTFul data service.

7.2.1. JSON

JSON, which stands for JavaScript Object Notation, is a lightweight data format that is in plaintext and human readable (as opposed to a binary format like AMF). Being lightweight, it is a faster data transport than XML but not as fast as a binary format. JSON is based on a subset of the JavaScript Programming Language, Standard ECMA-262, 3rd edition. JSON can be used for data storage both local to the AIR application or on a remote server. This Chapter will focus on reading JSON data from a remote server by using the <mx:HTTPSevice> tag. To work with local data in JSON format, please refer to the file reading and writing examples in Chapter 8. If you read the file in via FileStream, you can run the same parsing function to extract data into an ActionScript array. To save the data back to the file system, you would simply use the encode() static method of the JSON class.

Listing 7-6 is an example of a JSON file.

Example 7-6. Example showing people.json
[{"lastName":"Tretola","firstName":"Rich"},{"lastName":"Tretola","firstName":"Kim"} ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required