JavaScript 30 JSON 02

示例 1 : 

创建JSON数组

通过方括号[] 创建JSON 数组

<script>
 
var heros=
[
    {"name":"盖伦","hp":616},
    {"name":"提莫","hp":313},
    {"name":"死歌","hp":432},
    {"name":"火女","hp":389}
]
 
document.write("JSON数组大小"+heros.length);
 
</script>

 

 示例 2 : 

访问JSON数组

访问JSON数组和访问普通数组一样,通过下标访问

<script>
  
var heros=
[
    {"name":"盖伦","hp":616},
    {"name":"提莫","hp":313},
    {"name":"死哥","hp":432},
    {"name":"火女","hp":389}
]
  
document.write( "第4个英雄是:" +  heros[3].name);
  
</script>

 示例 3:

 

 数组里包含对象:

 

 

可以用json.cn 来做json的校验

posted @ 2020-07-26 10:28  Jasper2003  阅读(155)  评论(0编辑  收藏  举报