Skip to content

Commit 84e3c21

Browse files
committed
Web:解决format返回格式错乱;修改基地址
1 parent 7a67e0a commit 84e3c21

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

APIJSON-JavaScript/RequestUtil.js

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
const TAG_REQUEST_UTIL = 'RequestUtil';
55

6-
const URL_BASE = "http://139.196.140.118:8080"; // 基地址
6+
const URL_BASE = "http://39.108.143.172:8080"; // 基地址
77
const URL_GET = URL_BASE + "/get"; // 常规获取数据方式
88
const URL_HEAD = URL_BASE + "/head"; // 检查,默认是非空检查,返回数据总数
99
const URL_GETS = URL_BASE + "/gets"; // 通过POST来GET数据,不显示请求内容和返回结果,一般用于对安全要求比较高的请求
@@ -135,15 +135,44 @@ function encode(json) {
135135

136136

137137
/**格式化JSON串
138-
* @param json {},JSON对象
138+
* @param json
139139
*/
140140
function format(json) {
141-
if ((json instanceof Object) == false) {
142-
alertOfDebug("format json instanceof Object == false >> json = parseJSON(json);");
143-
json = parseJSON(json);
141+
try {
142+
return JSON.stringify(JSON.parse(json), null, "\t");
143+
} catch(e) {
144+
log(TAG_REQUEST_UTIL, 'format try { ... } catch (err) { \n ' + e);
145+
return json;
144146
}
145147

146-
return JSON.stringify(json, null, "\t");
148+
// 导致格式化后代码很难看,像没格式化一样
149+
// if (json == null || json == '') {
150+
// console.log('format json == null || json == "" >> return json;');
151+
// return json;
152+
// }
153+
//
154+
// if (json instanceof Object) { //避免赋值影响传进来的json
155+
// return JSON.stringify(json, null, "\t");
156+
// }
157+
//
158+
// var jsonObj;
159+
// if (typeof json == 'string'){
160+
// try {
161+
// jsonObj = JSON.parse(json);
162+
// } catch (err) {
163+
// console.log('format try { jsonObj = JSON.parse(json); } catch (err) { \n ' + err);
164+
// return json;
165+
// }
166+
// }
167+
// else {
168+
// console.log('format json type error !');
169+
// return json;
170+
// }
171+
// return JSON.stringify(jsonObj, null, "\t");
172+
}
173+
174+
function log(tag, msg) {
175+
console.log(tag + '.' + msg);
147176
}
148177

149178
/**将json字符串转为JSON对象

0 commit comments

Comments
 (0)