文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Json对象替换字符串占位符

Json对象替换字符串占位符

时间:2010-11-15  来源:czonechan

例如:

  含有占位符的字符串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而不是空。
            });
        }; 

相关阅读 更多 +
排行榜 更多 +
涂色我贼强安卓版

涂色我贼强安卓版

休闲益智 下载
脑细胞太牛了手机版

脑细胞太牛了手机版

休闲益智 下载
球球的冒险旅途

球球的冒险旅途

休闲益智 下载