admin管理员组文章数量:1335092
How to remove the null value in json string using jquery
var jsonstring=[null,null,{"rank":"23","credit":"10"},null,null,{"rank":"26","credit":"10"},null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,{"rank":"31","credit":"05"}]
How to remove the null value in json string using jquery
var jsonstring=[null,null,{"rank":"23","credit":"10"},null,null,{"rank":"26","credit":"10"},null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,{"rank":"31","credit":"05"}]
- unjson, remove null, json again? – sectus Commented Apr 23, 2015 at 10:02
- 1 javascript solution to your question: stackoverflow./questions/281264/… – Pawan Commented Apr 23, 2015 at 10:02
- You can try this on:- jsonstring=JSON.stringify(jsonstring).replace(/null/g,' '); jsonstring.replace(/ ,/g,'') – Tanul Commented Apr 23, 2015 at 10:29
- Please give the example for my jsonstring – vengatesh rkv Commented Apr 23, 2015 at 10:45
3 Answers
Reset to default 4var arr = JSON.parse(json_string);
arr = arr.filter(function(n){ return n });
json_string = JSON.stringify(arr)
Use like this
(function filter(obj) {
$.each(obj, function(key, value){
if (value === "" || value === null){
delete obj[key];
} else if (Object.prototype.toString.call(value) === '[object Object]') {
filter(value);
} else if ($.isArray(value)) {
$.each(value, function (k,v) { filter(v); });
}
});
})(sjonObj);
You should use array access notation please see the below code
delete sjonObj[key];
$.each(sjonObj, function(key, value){
if (value === "" || value === null){
delete sjonObj[key];
}
});
Thanks
本文标签: javascriptHow to remove the null value in json string using jqueryStack Overflow
版权声明:本文标题:javascript - How to remove the null value in json string using jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742384108a2464681.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论