【发布时间】:2019-03-04 00:47:46
【问题描述】:
我想从 Web 服务器解析 JSON 格式的数据集(在 Electron renderer.js 文件中编辑)
refresh.addEventListener("click", function(){
const http = require('http');
http.get(
'http://teamparamount.cn:8080/Paramount/filesroot?username=test', (resp) =>{
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) =>{
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () =>{
// console.log(JSON.parse(data).info);
// var obj = JSON.stringify(data);
var hhh = JSON.parse(data);
var xxx = JSON.parse(data).info;
// alert(typeof obj);
// console.log(hhh.length);
// console.log(obj);
console.log(data);
console.log(hhh.status);
console.log(hhh.info);
console.log(hhh.info[1].time);
console.log(hhh.info.length);
console.log(hhh.info[408]);
// console.log(obj.info[1]);
// console.log(obj.status);
// console.log(obj.status.length);
function getJsonLth(obj){
var index = 0;
for(var i=0;i<obj.length;i++){
if (obj[i] == ':') {
index++;
}
return index;
// alert(json1.abc[i].name);
}
};
console.log(getJsonLth(xxx));
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
});
【问题讨论】:
标签: javascript node.js json electron