[置顶] JSON 在javascript中使用json

JSON举例(javascript中使用json)

1.简单的例子:

<scripttype="text/javascript">
var usre={"id":1,"name":"you","ide":"eclipse"}
alert(usre.id);
alert(usre[“name”’]);
</script>

2.为 id 属性添加更详细的信息:

"id":{ “no”:1,”dizhi”:”山东省”};

3.为 id 属性定义成数组:


”id”: [  

           { “no”:1,”dizhi”:”山东省”},
           { “no”:2,”dizhi”:”海南省”}

       ]

4.多用户列表:

var usre = [  {"id":1,"name":"you","ide":"eclipse"},
                     {"id":2,"name":"ken","ide":"VB"}       ]
例子:

<p>
Name: <span id="name"></span><br />
Age: <span id="age"></span><br />
Address: <span id="end"></span><br />
Phone: <span id="phone"></span><br />
</p>

<script type="text/javascript">
   var JSONObject= {
        "name":"Bill Gates",
        "end":"Fifth Avenue New York 666",
        "age":56,
        "phone":"555 1234567"};
document.getElementById("name").innerHTML=JSONObject.name
document.getElementById("age").innerHTML=JSONObject.age
document.getElementById("end").innerHTML=JSONObject.end
document.getElementById("phone").innerHTML=JSONObject.phone
</script>


你可能感兴趣的:(JavaScript,json,例子,JSON干嘛用)