码迷,mamicode.com
首页 > 编程语言 > 详细

javascript json

时间:2017-06-17 16:02:49      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:logs   nbsp   rip   数据   ima   json对象   fine   http   方法   

技术分享

 

技术分享

 

技术分享

 

技术分享

 

循环json对象的值

var json1 = {
    "name": "jiao",
    "age": 25,
    "man": true,
    "things": {
        "thing1": "violin",
        "thing2": "coding"
    }
}

for(attr in json1){
    console.log(json1[attr]);
}

 

json对象中数据的修改

var json1 = {
    "name": "jiao",
    "age": 25,
    "man": true,
    "things": {
        "thing1": "violin",
        "thing2": "coding"
    }
}

delete json1.things.thing1;
json1.things.thing3 = "haha";
console.log(json1.things);

 

 

json数组

var json1 = {
    "name": "jiao",
    "age": 25,
    "man": true,
    "things": {
        "thing1": "violin",
        "thing2": "coding"
    },
    "arr": [
        "site1", "site2", "site3", "site4"
    ]
}

for(var i = 0; i < json1.arr.length; i++){
    console.log(json1.arr[i]);
}

教程中说可以使用delete关键字删除数组元素。可我删除了之后数组长度不变,被删除的元素变为undefined,占位仍在。

似乎只能用正常的数组方法来解决这个问题了。

 

javascript json

标签:logs   nbsp   rip   数据   ima   json对象   fine   http   方法   

原文地址:http://www.cnblogs.com/jiaoxuanwen/p/7040302.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!