JSON Basic Learning

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"
"Http://www.w3.org/TR/html4/loose.dtd" >
<p>name:<span id= "Jname" ></span></br>
Adg:<span id= "Jage" ></span></br>
Address:<span id= "Jaddress" ></span></br>
Phone:<span id= "Phone" ></span></br>
</p>
<title></title>
<!--<link href= "css.css" type= "Text/css" rel= "stylesheet"/>-->
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<!--<script language= "JavaScript" src= "Js1.js" ></script>-->
<script >
var json1={
' Name ': ' Bug loose ',
' Addres ': ' Firth Avenue New York 555 ',
' Age ': ' 100000 ',
' Phone ': ' 110 120 119 114 10001 '
};
document.getElementById (' Jname '). Innerhtml=json1.name
document.getElementById (' Jage '). Innerhtml=json1.age
document.getElementById (' jaddress '). Innerhtml=json1.addres
document.getElementById (' phone '). Innerhtml=json1.phone
JSON array mode
var obj1=[
{' obj ': [obj2], ' 123},{':
' List ': ["tuple", one], ' Tuple1 ': [(1), [2.3,2]]
}
]
Accessing the specified array in array

Alert (Obj1[1].tuple1[1][1])
String manipulation


</script>
<body>
Name:<span id= "Names" ></span></br>

<script>
var txt = ' {' Employees ': [' +
' {' firstName ': ' Bill ', ' lastName ': ' Gates '}, ' +
' {' firstName ': ' George ', ' lastName ': ' Bush '}, ' +
' {' firstName ': ' Thomas ', ' lastName ': ' Carter '}]} ';
var obj=eval ("(" +txt+ ")");//or change to obj = Json.parse (txt);
Because Eval () will present a hidden danger
var obj=json.parse (TXT)



document.getElementById (' names '). Innerhtml=obj.employees[1].firstname
</script>
</body>
Other JSON learning

JSON the Format :

1, object:

{Name: "Peggy", email: "[email protected]", homepage: "Http://www.peggy.com"}

{property: Value, Property: Value, property: Value}

2, the array is a collection of sequential values. An array starts at "[", Ends with "]", and the values are separated by ",".

[

{Name: "Peggy", email: "[email protected]", homepage: "Http://www.peggy.com"}, {name: "Peggy", email: "[email protected]" , homepage: "Http://www.peggy.com"},

{Name: "Peggy", email: "[email protected]", homepage: "Http://www.peggy.com"}

]

3, the value can be a string, a number, true, false, NULL, or it can be an object or an array. These structures can be nested.

JSON Basic Learning

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.