clq
浏览(534) -
2019-11-22 15:57:01 发表
编辑
关键字:
[js]处理 json 中的特殊字符
//--------------------------------------------------
//返回的 json 格式要处理一下
//https://www.cnblogs.com/xiaojiumei/p/10214692.html
/*
JSON.parse()处理json字符串时需要处理的特殊字符
var str= "json字符串";
str=str.replace(/\\/g,"\\\\");
str=str.replace(/\n/g,"\\n");
str=str.replace(/\r/g,"\\r");
str=str.replace(/\t/g,"\\t");
str=str.replace(/("")+/g,"\"\"");
str=str.replace(/\'/g,"'");
str=str.replace(/ /g," ");
str=str.replace(/str=str.replace(/>/g,">");
console.log(JSON.parse(str))
*/
//mixed str_replace( mixed search, mixed replace, mixed string [, int &count] )
//
function FormatForJson($str)
{
$str = str_replace("\\","\\\\", $str);
$str = str_replace("\n","\\n", $str);
$str = str_replace("\r","\\r", $str);
$str = str_replace("\t","\\t", $str);
$str = str_replace("\"","\\\"", $str);
$str = str_replace("\'","'", $str);
$str = str_replace(" "," ", $str);
$str = str_replace("<","<", $str);
$str = str_replace(">",">", $str);
return $str;
}//
//这个的算法其实是清空特殊标识
function FormatForJson_v2($str)
{
$str = str_replace("\\","", $str);
$str = str_replace("\/","", $str);
$str = str_replace("/","", $str);
$str = str_replace("\n","", $str);
$str = str_replace("\r","", $str);
$str = str_replace("\t","", $str);
$str = str_replace("\"","", $str);
$str = str_replace("\'","", $str);
$str = str_replace(" "," ", $str);
$str = str_replace("<","", $str);
$str = str_replace(">","", $str);
return $str;
}//
//echo FormatForJson("aaa<\"aaa");
本帖子属于以下条目()
NEWBT官方QQ群1: 276678893
可求档连环画,漫画;询问文本处理大师等软件使用技巧;求档softhub软件下载及使用技巧.
但不可"开车",严禁国家敏感话题,不可求档涉及版权的文档软件.
验证问题说明申请入群原因即可.