源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Json对象替换字符串占位符实现代码

  • 时间:2021-06-16 06:35 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Json对象替换字符串占位符实现代码
例如:   含有占位符的字符串hello,{name},your birthday is {birthday };   提供的Json对象{name: "czonechan", birthday : "1989-07-02" } ;   替换后为 hello,czonechan,your birthday is 1989-07-02。 实现代码:
[u]复制代码[/u] 代码如下:
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而不是空。 }); };
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部