|
3 | 3 | */ |
4 | 4 | const TAG_REQUEST_UTIL = 'RequestUtil'; |
5 | 5 |
|
6 | | -const URL_BASE = "http://139.196.140.118:8080"; // 基地址 |
| 6 | +const URL_BASE = "http://39.108.143.172:8080"; // 基地址 |
7 | 7 | const URL_GET = URL_BASE + "/get"; // 常规获取数据方式 |
8 | 8 | const URL_HEAD = URL_BASE + "/head"; // 检查,默认是非空检查,返回数据总数 |
9 | 9 | const URL_GETS = URL_BASE + "/gets"; // 通过POST来GET数据,不显示请求内容和返回结果,一般用于对安全要求比较高的请求 |
@@ -135,15 +135,44 @@ function encode(json) { |
135 | 135 |
|
136 | 136 |
|
137 | 137 | /**格式化JSON串 |
138 | | - * @param json {},JSON对象 |
| 138 | + * @param json |
139 | 139 | */ |
140 | 140 | 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; |
144 | 146 | } |
145 | 147 |
|
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); |
147 | 176 | } |
148 | 177 |
|
149 | 178 | /**将json字符串转为JSON对象 |
|
0 commit comments