Ext.encode and Ext.decode.

Source: Internet
Author: User

Ext.encode (Mixed O): String:json object Conversion JSON string Ext.decode (String json): Object:json string Conversion JSON object

Instance

HTML code
  1. <body>
  2. <form id="Form1" runat="Server">
  3. <div>
  4. <script type="Text/javascript">
  5. function Ready ()
  6. {
  7. Another example illustrates how to use decode and encode, and now we know what the JSON data format is, and what it does and what it does.
  8. Now let's get to the drill.
  9. Use the Decode method first, which is to convert the JSON string into an object's
  10. First step: Define a JSON string first.
  11. var Liu King = "{name: ' Andy Lau ', Sex: ' Male ', Hometown: ' Hong Kong '}";
  12. Step two: Now we're going to convert the king to a target.
  13. var who = Ext.decode (Liu Tianwang);
  14. 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
  15. var name = who . Name; Get the [name] property of the Who object
  16. var sex = who . gender; Get the [gender] property of the Who object
  17. var home = who . Home; Get the [home] property of the Who object
  18. Fourth step: Combine the information obtained below
  19. var result = "The information of the Liu King's information: name is-" +name + "; gender-" +sex+ "; hometown-" +home;
  20. The fifth step: we show the information of the WHO object we get with the pop-up message.
  21. Ext.Msg.alert ("Liu King's information", result);
  22. The above is an example of converting a JSON string into an object and then accessing the properties of the object individually
  23. Use the Encode method below
  24. The Encode method is simple enough to convert the WHO object generated above into the JSON string defined in the first step
  25. Define a function to time execution
  26. var getjson = function ()
  27. {
  28. 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
  29. var jsonstr = Ext.encode (WHO);
  30. Let's just show this JSON string in the form of a popup message.
  31. Ext.Msg.alert ("Jsonstr information content", JSONSTR);
  32. };
  33. The following method means: After 3 seconds, the function Getjson executes the script contained inside.
  34. SetTimeout (getjson,3000);
  35. Add something.
  36. Ext.decode () and Ext.encode () are shorthand for Ext.util.JSON.decode () and Ext.util.JSON.encode, respectively
  37. }
  38. Ext.onready (Ready);
  39. </Script>
  40. </div>
  41. </form>
  42. </body>

Ext.encode and Ext.decode.

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.