Full manual text for JSON Learning

Source: Internet
Author: User

Chapter 1 What is josn
JSON: JavaScript Object Notation

It is a data structure that describes object data (various metadata is actually the simplest object) in JavaScript (such as JScript and ECMA JavaScript. The concept and usage are similar to hash (hash table) or associated array.

JSON is constructed in two structures:

A collection of name/value pairs ). In different languages, it is understood as an object, record, struct, dictionary, and hash table ), keyed list or associative array ).
An ordered list of values ). In most languages, it is understood as an array ).
These are common data structures. In fact, most modern computer languages support them in some form. This makes a data format based on these structuresProgramming LanguageExchange between them becomes possible.

The simplest JSON example is as follows:

CopyCode The Code is as follows :[
{Name: "Michael", email: "17bity@gmail.com", homepage: "http://www.jb51.net "},
{Name: "John", email: "john@gmail.com", homepage: "http://s.jb51.net "},
{Name: "Peggy", email: "peggy@gmail.com", homepage: "http://tools.jb51.net"}]

The following example describes a mail contact list. When Javascript is run with Eval, A maillist object entity is obtained, and javascript can be used for further operations.

Copy code The Code is as follows: var maillist = [
{Name: "Michael", email: "17bity@gmail.com", homepage: "http://www.jb51.net "},
{Name: "John", email: "john@gmail.com", homepage: "http://s.jb51.net "},
{Name: "Peggy", email: "peggy@gmail.com", homepage: "http://tools.jb51.net "}
]

You can use JavaScript For further operations.

Chapter 2 JSON format

The basic JSON format is as follows:
An object is a set of attributes and value pairs. An object starts with "{" and ends "}". Each attribute name and value is separated by a ":" prompt, and.

An array is a set of ordered values. An array starts with "[", ends with "]", and values are separated.

The definition of a string is basically the same as that of C or Java.

The definition of numbers is also basically the same as that of C or Java.

Chapter 3 Use trimpath template to create a JSON Template

Trimpath template is a lightweight js code used to parse JSON data and generate webpage code.

Demo: http://demo.jb51.net/js/js_template/test.htm

Trimpath. template is JavaScript-based, cross-browser, open with APL/GPLSource codeProtocol allows you to easily implement a pure JS Engine Based on Template programming.

Http://code.google.com/p/trimpath/

It has the following features:

1. It is written in standard JavaScript and supports cross-browser
2. The template syntax is similar to freemarker, velocity, and smarty.
3. Use a simple language to describe large-segment strings and DOM/DHTML operations
4. You can easily parse the data in the XML file format to the specified template.

This engine can be used to completely handle view tasks. The server module can directly output data. Making your MVC model integrated, and because the view is handled by the browser, greatly reducing the burden on the server, it is a good choice to build the Network Information System Application of Ajax technology.

This is a simple and small template tool class to help users quickly assemble the required strings.

Simple Description #{... /} data is executed as JS scripts, and the VaR keyword indicates the value of seed (a variable value passed in from outside ).
The template is divided into two parts for execution. The part between compile and run. # {.../} is executed during run,
The part between #{#.../} cannot be passed into seed.
I don't need to write more instructions, because it is really simple.

Principle: it is actually to use the input parameters #{.... (#{... ).

If you are interested in the template technology, you can study the code to get more inspiration.

Summary

As the default JavaScript data format, JSON is very convenient for Ajax operations and much smaller than XML files. Therefore, when the network speed is not ideal and the coupling degree of the system is relatively high, the performance is better.

However, XML is a self-descriptive format and is widely used in the world. So when the system requires cross-platform, cross-language, XML is still the best choice.

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.