json格式处理及扩展
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.js"></script> <script> //json扩展方法 if (!Object.prototype.forEach) { Object.prototype.forEach = function (fn) { try { for (var key in this) { //确定某属性是否是对象本身的属性。 if (this.hasOwnProperty(key)) { fn.call(this, key, this[key]); //fn.apply(this, [key, this[key]]); } } } catch (e) { throw e; } } } </script>JSON扩展
<script> var stringeap = '{"name":"小明","age":"20"}'; var jsoneap = { name: '小明', age: '' }; //json删除 delete jsoneap["name"];//或者 delete jsoneap.name; //json添加修改 jsoneap.name = "小王";//或jsoneap["name"]="小王" //判断json中的key是否存在 console.log(jsoneap.hasOwnProperty("name")); //js处理json方式 //转标准格式json var data = JSON.parse(stringeap); //jq方式 var dat= $.parseJSON(stringeap) var data1 = eval("(" + stringeap + ")"); //转json字符串 var stringdata = JSON.stringify(jsoneap); jsoneap.forEach(function (key, value) { console.log(key, value); }); </script>
相关推荐
88286632 2020-07-12
HanksWang 2020-11-10
jackbon 2020-10-19
lmllouk 2020-11-02
anglehearts 2020-09-09
聪聪李 2020-09-10
songshijiazuaa 2020-09-01
天空一样的蔚蓝 2020-08-24
xiancaione 2020-08-17
middleware0 2020-07-19
herohope 2020-07-18
AngelicaA 2020-07-04
数据与算法之美 2020-06-28
xhao 2020-06-28
mengtianbao 2020-06-27
ol0 2020-06-26
CSDNMrWang 2020-06-22
returnspace 2020-06-21