JSON-formatted strings converted to JSON strings

Source: Internet
Author: User

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

Related Article

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.