The data input model of JavaScript code. The selection is very limited when the date is serialized. I can: copy a JavaScript toString sequence that converts a date to a date, for example, Sunday, October 21, 2007 12:34:28 GMT-0700 (PDT), by date in the form presented in the Atom document.
The first two options can be processed in JavaScript, without the need for developers to do too much work. That is to say, to obtain the correct JavaScript Date object, you only need to call the new Date (feed. updated ). However, the disadvantage is that using the first option will lose important information related to milliseconds and Time Zone offset;
If the second option is used, the toString sequence of the date is different from that of the region. Although using the RFC 3339 sequence requires additional work, this is the only option to avoid data loss and unclear meaning.
Text Structure
Atom supports a large number of text and content options. So far, this is the most complex and difficult problem encountered during JSON serialization. Text structures, such as title, subtitle, summary, and rights elements, can contain plain text, escape HTML, or JavaScript code. These structures are language-sensitive, so the xml: lang attribute must be considered;
- Introduction to JSON parser Processing Using Servers
- Describes the usage characters of a JSON object.
- Summary of the usage tips and descriptions of the JSON definition method
- Describes in detail the features of JSON structure formats
- JSON numeric structure description
In addition, HTML and XHTML tags can contain the relative URI to be parsed. The Atom content element supports Base64 encoded content, any XML tag, and external content referenced using the src attribute, which makes the serialization process more difficult.
The purpose of JSON serialization of Atom content is to find a common representation method that can capture these options as consistently as possible. Listing 18 shows an example of a feed with three types of text structures.
- <updated>2007-10-14T12:12:12Z</updated>
The title element is plain text. It must inherit the Language Context of the abstract; otherwise, it is not descriptive. The subtitle element contains the escape HTML Tag. The right element is also plain text, but it overwrites the language context. Listing 19 shows the JavaScript code for these three elements.
- <feed xmlns="http://www.w3.org/2005/Atom"> ...
- <title>Example Feed</title> <subtitle type="html"><p>This is an example feed</p></subtitle>
- <rights xml:lang="fr">...</right> ...</feed>
Note that this is only the simplest case. The title is serialized as a simple string. However, since the language context in the right element changes at all times, although it is plain text, it is also serialized as an object that contains two fields attributes and children.
For the subtitle element, the JavaScript code mark is parsed and presented as a layered structure. The XHTML tag also uses the same structure list 20 and 21 ).
- { "title":"Example Feed", "subtitle":{ "attributes":{ "type":"html" },
-
- "children":[ { "name":"p", "attributes":{ }, "children":["This is an
-
- example feed" ] } ] }, "rights":{ "attributes":{ "lang":"fr" },
-
- "children":[ "..." ] } }