例如:
含有占位符的字符串hello,{name},your birthday is {birthday };
提供的Json对象{name: “czonechan”, birthday : “1989-07-02” } ;
替换后为 hello,czonechan,your birthday is 1989-07-02。
实现代码:
复制代码 代码如下:
Object.prototype.jsonToString=function(str) {
o=this;
return str.replace(/\{\w*\}/g, function (w) {
r = w.substr(1,w.length-2);//去除{}
return (o[r]===0)?0:(o[r] ? o[r] : “”);//o[r]===0这句是为了实现当值为0时输出0而不是空。
});
};
来源链接:https://www.jb51.net/article/25300.htm
© 版权声明
本站所有资源来自于网络,仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您(转载者)自己承担!
如有侵犯您的版权,请及时联系3500663466#qq.com(#换@),我们将第一时间删除本站数据。
如有侵犯您的版权,请及时联系3500663466#qq.com(#换@),我们将第一时间删除本站数据。
THE END
暂无评论内容