qooxdoo Beginner's Guide
上QQ阅读APP看书,第一时间看更新

Passing data to the server

qooxdoo uses the JSON format to transfer the data between the client browser and the web server. JSON is a light-weight data interchange format. JSON is very light when compared to the XML format. It is easy for humans to read and write. It is easy for machines to parse and generate. We have mentioned the JSON standard format in this section. This information is good enough to work with JSON. If you want to read more, you can visit the JSON website (http://www.json.org/).

JSON standard format

The Date object is an exception in the formatting as JavaScript does not have a literal syntax for the Date object.

Date objects are sent as the following tokens:

  • The string—new Date (Date.UTC(
  • The year, integer; for example, 2006
  • A comma
  • The month, 0-relative integer; for example, 5 (that is, June)
  • A comma
  • The day of the month, integer, range: 1-31
  • A comma
  • The hour of the day on a 24-hour clock, integer, range: 0-23
  • A comma
  • The minute of the hour, integer, range: 0-59
  • A comma
  • The second within the minute, integer, range: 0-59
  • A comma
  • The milliseconds within the second, integer, range: 0-999
  • The string—))

A resulting date representation might therefore be:

new Date(Date.UTC(2006,5,20,22,18,42,223))

While working with date strings, you must take care with the following:

  • Whitespace: The following points should be remembered:
    • When generating these date strings, implementations should not add whitespace before, after, or between any of the fields within the date string.
    • When parsing these date strings, implementations should allow whitespace before, after, or between any of the fields within the date string.
  • Numbers: The following points should be remembered:
    • When generating these date strings, implementations must not add leading zeros to the numeric values in the date string. Doing so will cause them to be parsed as octal values. Numbers must be passed in decimal (base 10) notation without leading zeros.
    • When parsing these date strings, implementations must take the integer value of numeric portions of the string as base 10 values, even if leading zeros appear in the string representation of the numbers.

Within the JSON protocol and in JSON messages between peers, Date objects are always passed in UTC format.

A sample JSON content to explain the file menu contents that contain the members, pairs, values or strings, arrays, and so on in the JSON format is as follows:

{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}}

What just happened?

We got to know about the data format that is passed between client and server in qooxdoo applications.