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