For example:
String containing placeholders hello, {name}, your birthday is {birthday };
Provided Json object {name: "czonechan", birthday : "1989-07-02 " } ;
Replaced with hello, czonechan, your birthday is 1989-07-02.
Implementation code:
Object.prototype .jsonToString=function(str) {
o=this;
return str.replace(/{w*}/g, function (w) {
r = w.substr(1,w.length -2);//Remove {}
return (o[r]===0)?0:(o[r] ? o[r] : "");//o[r]=== The purpose of 0 is to output 0 instead of empty when the value is 0.
});
};