|
@@ -28,6 +28,12 @@ baidu.csJsonFormat = (function () {
|
|
|
jQuery('<link id="_fehelper_fcp_css_" href="' + fcpCss + '" rel="stylesheet" type="text/css" />').appendTo('head');
|
|
|
};
|
|
|
|
|
|
+ var _unEscapeHTML = function(txt) {
|
|
|
+ return txt.replace(/&/g,'&').replace(/>/g,'>')
|
|
|
+ .replace(/</g,'<').replace(/"/g,'"')
|
|
|
+ .replace(/'/g,"'");
|
|
|
+ };
|
|
|
+
|
|
|
/**
|
|
|
* 从页面提取JSON文本
|
|
|
* @return {*}
|
|
@@ -41,6 +47,8 @@ baidu.csJsonFormat = (function () {
|
|
|
if (!source) {
|
|
|
return;
|
|
|
}
|
|
|
+ // jQuery的html方法是把内容编码后输出的,所以需要反解回去
|
|
|
+ source = _unEscapeHTML(source);
|
|
|
|
|
|
// 如果body的内容还包含HTML标签,肯定不是合法的json了
|
|
|
// 如果是合法的json,也只可能有一个text节点
|
|
@@ -56,7 +64,7 @@ baidu.csJsonFormat = (function () {
|
|
|
}
|
|
|
} else if (nodes[i].nodeType == Node.ELEMENT_NODE) {
|
|
|
var tagName = nodes[i].tagName.toLowerCase();
|
|
|
- var html = $.trim($(nodes[i]).html());
|
|
|
+ var html = $.trim(_unEscapeHTML($(nodes[i]).html()));
|
|
|
// 如果是pre标签,则看内容是不是和source一样,一样则continue
|
|
|
if(tagName === 'pre' && html === source) {
|
|
|
continue;
|
|
@@ -127,6 +135,7 @@ baidu.csJsonFormat = (function () {
|
|
|
|
|
|
$('body').html(_htmlFragment);
|
|
|
_loadCss();
|
|
|
+
|
|
|
JsonFormatEntrance.clear();
|
|
|
JsonFormatEntrance.format(source);
|
|
|
|