<! 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