forked from do-project/code4do
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
42 lines (38 loc) · 1.08 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var d1 = require("deviceone");
// 声明
module.exports.init = init;
module.exports.getResponseData = getResponseData;
module.exports.printJSON = printJSON;
var app = d1.sm("do_App");
var page = d1.sm("do_Page");
function init(ui_id) {
var close = d1.ui(ui_id);
close.on("touch", function() {
app.closePage();
})
page.on("back", function(data) {
app.closePage();
})
}
function getResponseData(data) {
var d = {};
var obj = JSON.parse(data.data);
d["status"] = "返回status:" + data.status;
d["request_header"] = "返回request的header:\n" + printJSON(obj.request.header);
d["request_parameters"] = "返回request的parameters:\n"
+ printJSON(obj.request.parameters);
d["request_body"] = "返回request的body:\n" + printJSON(obj.request.body);
d["response_header"] = "返回response的header:\n"
+ printJSON(obj.response.header);
d["response_data"] = "返回response的data:\n" + printJSON(obj.response.data);
return d;
}
function printJSON(obj) {
if (typeof obj == "string")
return obj;
var a = "";
for ( var x in obj) {
a = a + x + "=" + obj[x] + "\n";
}
return a;
}