Detailed JavaScript code display of JSON serialized text

Source: Internet
Author: User

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.

 
 
  1. <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.

 
 
  1. <feed xmlns="http://www.w3.org/2005/Atom">   ... 
  2.  <title>Example Feed</title>  <subtitle type="html"><p>This is an example feed</p></subtitle> 
  3.  <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 ).

 
 
  1. {  "title":"Example Feed",   "subtitle":{     "attributes":{       "type":"html"     },       
  2.  
  3. "children":[      {         "name":"p",         "attributes":{ },         "children":["This is an   
  4.  
  5. example feed" ]       }     ]  },  "rights":{    "attributes":{      "lang":"fr"    },      
  6.  
  7. "children":[      "..."    ]  } } 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.