1 <%@ Page Language="Java"ContentType="text/html; Charset=utf-8"2 pageencoding="UTF-8"%>3 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd ">4 <HTML>5 <Head>6 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8">7 <title>Insert Title here</title>8 </Head>9 <Scripttype= "Text/javascript">Ten One //In the case of a JSON-formatted string sent by the server, the browser needs to perform a JSON string with eval ("(" +str+ ")") to parse it . A varStr= "{\ "name\": \ "Lisa\", \ "age\":"; - var Person=Eval ("(" +Str+ ")");//Convert a normal string into a JSON string - the //Alert (Person.name + "," + person.age); - - window.onload=function(){ - + varbtn=document.getElementById ("btn"); - + Btn.onclick= function() { A at varname1=document.getElementById ("name1"); - varAge1=document.getElementById ("Age1"); - - name1.innerhtml=person["name"]; - age1.innerhtml=person[" Age"]; - in /////////////////////////////////////////////////// - to varname2=document.getElementById ("name2"); + varAge2=document.getElementById ("Age2"); - the name2.innerhtml=Person.name; * age2.innerhtml=Person.age; $ };Panax Notoginseng }; - </Script> the <Body> + <ButtonID= "BTN">Get user name and age</Button> <BR/> A theName:<spanID= "Name1"></span><BR/> +Age:<spanID= "Age1"></span><BR/> --------------------------------------<BR/> $Name:<spanID= "Name2"></span><BR/> $Age:<spanID= "Age2"></span><BR/> - </Body> - </HTML>
JSON-formatted strings converted to JSON strings