Detailed instructions on JSON help

Source: Internet
Author: User

You have seen the powerful use of JSON in this article. JSON provides an excellent object-oriented method to cache metadata to the client. JSON helps to separate verification data and logic. JSON helps provide the essence of Ajax for Web applications.

 
 
  1. function addVehicleData() {  
  2.      var brand = //get vehicle brand;   var regNo = //get registration number;  
  3.       var cc = //get cc;  
  4.  
  5.       vehicleData[vehicleData.length] = new Object();  
  6.     vehicleData[vehicleData.length].brandName = new Object();  
  7.   vehicleData[vehicleData.length].brandName = brand;  
  8.    //same way update other two properties  
  9.  } 

Here, vehicleData is the JavaScript variable used for initialization when the user loads the page. It is initialized as a new array object, which is empty or contains vehicle elements of vehicles previously entered by the user.

When this function saves data to a JavaScript object, the program can call another function to clear the input field to allow users to enter new data.

In such applications, users are required to enter multiple groups or multi-value attributes that appear at least or most frequently. You can place these restrictions into JSON metadata objects. In this case, the previous metadata object is changed to the code shown in Listing 6.

 
 
  1. var vehicleValidationsMetadata = {  
  2.      "MIN_OCC":{0},  
  3.      "MAX_OCC":{10},  
  4.      "MAX_OCC_MSG":{"...."},  
  5.      "MIN_OCC_MSG":{".....},  
  6.      //Everything else is the same  
  7.  } 

Then, the addVehicleData () function first verifies the number of occurrences of the data, and then adds the data to the JavaScript Object only when the total number of occurrences does not exceed the allowed limit. Listing 7 shows the check method.

 
 
  1. function addVehicleData() {  
  2.    if(vehicleData.length == vehicleValidationsMetadata.MAX_OCC-1) {  
  3.           alert(vehicleValidationsMetadata.MAX_OCC_MSG);  
  4.      }  //Everything else is the same  

The function called when a user submits a page is actually used to verify the minimum number of occurrences. The biggest advantage of this method is that the screen does not need to be refreshed to input new vehicle data. Providing such static screens was once the main goal of Ajax technology, and now you can achieve this goal with JSON. This is about updating the JSON help object and processing all the content of the html dom tree through JavaScript. The user response time is the minimum value because all operations are only executed on the client. You can use JSON to provide Ajax functions for applications.

  • Detailed JavaScript code Display in JSON Sequence
  • Describes in detail the conversion of JSON serialization.
  • The author provides detailed instructions on the Json getting started document.
  • A full description of the JSON history
  • Comparison between JSON and XML

When you click the Save button, the program will call another JavaScript function, which will string this JSON object and store it to the hidden table field submitted by the program to the server. For details about JSON. js, see references.) There is a JSON. stringify () function that retrieves JavaScript objects as input and returns string output.

The server must be able to understand JSON help strings and generate a server-side object to process and save data. The Web site http://www.json.org/java/index.html provides a Java API that handles most of the needs of Java-based applications.

Related Article

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.