精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-12-12
最后修改:2008-12-12
Ajax is "asynchronous javascript and XML" has been well-known acronym,However, although XML is an important part of the look,It isn't necessary.A senior software engineer Douglas Crock ford developed a built-in javascript data format,That the object known as the javascript(JSON,Javascript Object Notation),Means that Ajax object to the use of direct transmission of information,Can be read as "Jason".
1.What is JSON subset of the grammar,That is, and the array of objects that.As a result of the use of grammar is javascript,Therefore, the definition of JSON can be included in the javascript file,Their visit without the need for XML-based language for additional analysis.However, before the use of JSON,It is important to understand the javascript array and the object literally in the amount of the special syntax.
1.1Array literal volume value of the javascript,Example:
1.2Literal target volume the brackets can be placed any number of "name - the value",Definition Format String Value.In addition to the last line outside,Each "name - the value of" there must be a comma after(Perl and in this joint array similar to the definition of some).Example:
1.3Mixed literal volume contains an array of objects.Example:
1.4JSON syntax access to the client after the eval method used to obtain this target, so that might dispense with the analysis of XML performance loss. At the same time, the use of javascript communications JSON data format as the star of the benefits are, you can immediately access the data value, the faster the access, including data. that the curly braces is a target rather than a statement of whether it is the only way to find it in parentheses package (which is used to describe the code is an expression rather than a statement).
1.5JSON encoding and decoding target directly and Javascript coding and decoding. The source tools can www.crockford.com / JSON / json.js download. the Javascript code into any evaluation and not just the JSON. As a result, when it comes to enterprise-class web application development, it's a big security risk. To solve this problem, you can use JSON code will only be used to convert the Javascript parser JSON.parse () methods to achieve. Example: "Kris"]}
it more simple.
Can easily find that many of the redundant information missing. As a result there is no need to start with the label (opening tag) to match the end of the label (closing tag), therefore, to send the same information needed to significantly reduce the number of bytes. Corockford its founder called "XML weight loss program"). JSON and XML data formats, for the layman readability shortcomings is even worse. Of course, there is a point of view is that the data exchange format is not observed with the naked eye. If the tool back and forth through the transmission of data to create and resolve, then indeed there is no reason for people to make the data must be easy to read. The essence of the problem lies: there are tools available JSON.
Download, it can be used in JSP.
4. JSON the strengths and weaknesses about by the performance and compatibility issues, but also for the javascript is very easy to use, can easily traverse through an array of objects, as well as access to property data acquisition, which also Readability good, with basic The structured nature of the data. Have to say is a good way to google maps and in fact there will be no transmission of data using XML, JSON instead of using the program. JSON Another advantage is the feasibility of cross-domain, for example, the page you www.xxx.com use is entirely feasible, which means you can cross-border transmission of information. And the use of XMLHttpRequest is not cross-domain access to information, javascript This is the nature of the internal security restrictions. and the reason is that the advantages of XML: versatility. To have a server-side grammar qualified javascript code is not easy, mainly took place in relatively large system, server and client have different developers. They must consult the target format, which is likely to result in errors. hope we can obtain great performance. 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
浏览 1741 次