【json】json基础知识

json语法详见j菜鸟教程

关于json的一些基础知识储备


<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)title>
head>
<body>
<h2>JavaScript 创建 JSON 对象h2>
<p>
网站名称: <span id="jname">span><br /> 
网站地址: <span id="jurl">span><br /> 
网站 slogan: <span id="jslogan">span><br /> 
p>
<div id="demo">div>
<div id="demo1">div>
<script>
var JSONObject= {
    "name":"菜鸟教程",
    "url":"www.noob.com", 
    "slogan":"学的不仅是技术,更是梦想!"
};
    var obj={
        "sites": [
            {"name":"菜鸟教程aa","url":"###","slogan":null},
            {"name":"菜鸟教程bb","url":"###","slogan":null}
        ]
    }
    var x = obj.sites[0].name;
    var y = "";
    for (i in obj.sites) {
        y += obj.sites[i].name + "
"
; } document.getElementById("jname").innerHTML=JSONObject.name document.getElementById("jurl").innerHTML=JSONObject.url document.getElementById("jslogan").innerHTML=JSONObject.slogan document.getElementById("demo").innerHTML = x; document.getElementById("demo1").innerHTML = y;
script> body> html>

你可能感兴趣的:(web)