Print program JavaScript notes Ext.decode and Ext.encode

Source: Internet
Author: User

Use the Decode method first, which is to convert the JSON string into an object's

First step: Define a JSON string first.
var Liu King = "{name: ' Andy Lau ', Sex: ' Male ', Hometown: ' Hong Kong '}";

Step two: Now we're going to convert the king to a target.
var who = Ext.decode (Liu Tianwang);

The third step: who became the object after the equivalent is the object of the class, the name, gender, home has become the WHO properties, now know how to access properties through the object bar
var name = who. Name; Get the [name] property of the Who object
var sex = who. gender; Get the [gender] property of the Who object
var home = who. Home; Get the [home] property of the Who object

Fourth step: Combine the information obtained below
var result = "The information of the Liu King's information: name is-" +name + "; gender-" +sex+ "; hometown-" +home;

The fifth step: we show the information of the WHO object we get with the pop-up message.
Ext.Msg.alert ("Liu King's information", result);

The above is an example of converting a JSON string into an object and then accessing the properties of the object individually

Use the Encode method below
The Encode method is simple enough to convert the WHO object generated above into the JSON string defined in the first step

Define a function to time execution
var Getjson = function ()
{
You can completely write this in the outside of the function, the reason is that it is purely to display the following message window 3 seconds after the first message box is displayed

var jsonstr = Ext.encode (WHO);

Let's just show this JSON string in the form of a popup message.
Ext.Msg.alert ("Jsonstr information content", JSONSTR);
};

The following method means: After 3 seconds, the function Getjson executes the script contained inside.

SetTimeout (getjson,3000);

Add something.

Ext.decode () and Ext.encode () are shorthand for Ext.util.JSON.decode () and Ext.util.JSON.encode, respectively

}
Ext.onready (Ready);

Print program JavaScript notes Ext.decode and Ext.encode

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.