PHP保存时过滤掉双引号&单引号&tab
function formartJsonString($jsonString = '') {
$jsonString = str_replace("'", "", $jsonString);
$jsonString = str_replace('\"', "", $jsonString);
$jsonString = str_replace('\t', "", $jsonString);
return $jsonString;
}
存储结果:
[{"title":"重点工作","content":"月落乌啼霜满天\n江枫渔火对愁眠"},{"title":"考核工作","content":""},{"title":"创新工作","content":""},{"title":"职能工作","content":""}]
javascript解析兼容性增强
jsonParse = function (str = '[]', defaultStr = '[]') {
if (str != '' && str != '[]' && str != '{}') {
str = str
.replace(/\n/g, "\\n")
.replace(/\r/g, "\\r")
.replace(/\t/g, "\\t")
return JSON.parse(str || defaultStr)
}
return JSON.parse(defaultStr)
}
标签:jsonString,title,text,defaultStr,replace,content,json,str,mysql
From: https://www.cnblogs.com/sunr/p/18184204