JSON and veal functions

Source: Internet
Author: User

One: JSON

(1) Create: Use {} to create;

(2) Function: Java background splicing JSON string, the JSON string sent to the browser, the browser's JS program can parse the JSON-formatted string, so that Java and JS to complete the communication;

1 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"2 "Http://www.w3.org/TR/html4/loose.dtd">3 <HTML>4 <Head>5 <Metahttp-equiv= "Content-type"content= "text/html; charset=gb2312">6 <title>Json</title>7 8     <Scripttype= "Text/javascript">9     Ten         //Json:javascript Object Notation[js objects tag] One         //JSON objects are created using: {}, which can create an untyped JavaScript object A         //JSON is typically used as a "Data interchange format" when exchanging data between languages -         //Javas the JSON string in the background, sends the JSON string to the browser, and the JS program in the browser can parse the JSON-formatted string. This enables Java and JavaScript to complete the communication -          the         varUser={ -          -             "Usercode": the, -             "username":"Jackson", +             " Age": - -          +         }; A          at         //accessing properties in an object - alert (user.username); - alert (user.usercode); - alert (user.age); -          -         /* in in JS [] represents the array, {} represents the JSON object -         */ to          +         //try to define a JSON object that stores information for all students in each class -         //required Description of the object: Total number of students, student's personal information the         //Student Personal information includes: School number, name *          $         varStus={Panax Notoginseng          -             " Total" : 5, the             "stups":[ +             {"Sno": the,"name":"Zhang San"}, A             {"Sno": -,"name":"John Doe"}, the             {"Sno": -,"name":"Harry"}, +             {"Sno": -,"name":"Zhao Liu"}, -             {"Sno": -,"name":"Zhu Eight"} $             ] $         } -          -          for(varI=0; I<Stus.stups.length;i++){ the          - Alert ("Name:"+Stus.stups[i].name+"School Number:"+Stus.stups[i].sno);Wuyi          the         } -          Wu     </Script> -  About </Head> $  - <Body> - </Body> - </HTML>
View Code

Two: the Eval function;

Function: eval (str); functions execute the str string as JS code;

Usage: Window.eval ("var i=100;");

1 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"2 "Http://www.w3.org/TR/html4/loose.dtd">3 <HTML>4 <Head>5 <Metahttp-equiv= "Content-type"content= "text/html; charset=gb2312">6 <title>eval function</title>7  8      <Scripttype= "Text/javascript">9     Ten         //eval ("str"); function executes the string as a JS code One Window.eval ("var name= ' Xu Zhiyuan ';");//Change the program quite var name= "Xu Zhiyuan"; A          - alert (name); -      the     </Script> -  - </Head> -  + <Body> - </Body> + </HTML>
View Code

JSON and veal functions

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.