javascript – dc.js以json格式将维度数据发送到node.js服务器,然后使用java处理数据
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – dc.js以json格式将维度数据发送到node.js服务器,然后使用java处理数据,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4456字,纯文字阅读大概需要7分钟。
内容图文
{"Account":"789","Date":"2013-07-31","Unique Id":"2013073101","Tran Type":"TFR OUT","Cheque Number":"","TranCode":"MB TRANSFER","ThirdPartyAccount":"123","Amount":"-20","formatedDate":"2013-07-30T12:00:00.000Z"}
{"Account":"789","Date":"2013-07-30","Unique Id":"2013073005","Tran Type":"TFR IN","Cheque Number":"","TranCode":"MB TRANSFER","ThirdPartyAccount":"123","Amount":"20","formatedDate":"2013-07-29T12:00:00.000Z"}
{"Account":"789","Date":"2013-07-30","Unique Id":"2013073004","Tran Type":"TFR OUT","Cheque Number":"","TranCode":"MB TRANSFER","ThirdPartyAccount":"123","Amount":"-20","formatedDate":"2013-07-29T12:00:00.000Z"}
{"Account":"789","Date":"2013-07-30","Unique Id":"2013073003","Tran Type":"CREDIT","Cheque Number":"","TranCode":"CREDIT","ThirdPartyAccount":"123","Amount":"20","formatedDate":"2013-07-29T12:00:00.000Z"}
{"Account":"789","Date":"2013-07-30","Unique Id":"2013073002","Tran Type":"TFR OUT","Cheque Number":"","TranCode":"MB TRANSFER","ThirdPartyAccount":"123","Amount":"-160","formatedDate":"2013-07-29T12:00:00.000Z"}
{"Account":"789","Date":"2013-07-30","Unique Id":"2013073001","Tran Type":"CREDIT","Cheque Number":"","TranCode":"CREDIT","ThirdPartyAccount":"123","Amount":"160","formatedDate":"2013-07-29T12:00:00.000Z"}
这是带有dc.js的crossfilter.js维度的输出,我想将此字符串发送到java程序以将其转换为json对象,然后我想读取数据并提取一些数据.以json格式将字符串发送回客户端.
这是如何创建输出
var dimData = accountDim.top(Infinity);
var dddata = [];
dimData.forEach(function (x) {
console.log(JSON.stringify(x));
dddata.push(JSON.stringify(x));
});
$.get(window.location.href + "toJSON?files=" + dddata.join(), function (){});
我的JAVA计划:
public static void main(String[] args) throws IOException, ParseException {
JSONParser parser = new JSONParser();
JSONObject jsons = (JSONObject) parser.parse(args[0]);
PrintWriter writer = new PrintWriter("res.json", "UTF-8");
writer.println(jsons);
writer.close();
}
这是我在node.js中的http服务器
var express = require('express');
var app = express();
app.use('/JS',express.static(__dirname + '/JS'));
app.use('/CSS',express.static(__dirname + '/CSS'));
app.use('/', express.static(__dirname + '/'));
app.get('/', function (req, res) {
// res.sendFile("/index.html");
}).listen(8080);
app.get('/toJSON', function(req, res, next) {
process.stdout.write('Extracting data to JSON...... ');
var files = req.query.files;
var spawn = require('child_process').spawn;
var child = spawn('java', ['-cp', 'Jarfile/CSVExtractor.jar:.', 'toJSON.ToJSON', files]);
process.stdout.write("done.\n");
child.stderr.on('data', function (data) {
process.stderr.write(data);
}).on('end', function() {
res.end();
});
child.stdout.on('data', function (data) {
res.write(data);
}).on('end', function() {
res.end();
});
});
我的问题是有没有更好的方法通过node.js将维度数据发送到java,如果没有,我怎么能像这样将字符串转换为json,然后检索数据?
有谁能够帮我?任何帮助,将不胜感激.
解决方法:
{"Account":"789","Date":"2013-07-31","Unique Id":"2013073101","Tran Type":"TFR OUT","Cheque Number":"","TranCode":"MB TRANSFER","ThirdPartyAccount":"123","Amount":"-20","formatedDate":"2013-07-30T12:00:00.000Z"}
{"Account":"789","Date":"2013-07-30","Unique Id":"2013073005","Tran Type":"TFR IN","Cheque Number":"","TranCode":"MB TRANSFER","ThirdPartyAccount":"123","Amount":"20","formatedDate":"2013-07-29T12:00:00.000Z"}
{"Account":"789","Date":"2013-07-30","Unique Id":"2013073004","Tran Type":"TFR OUT","Cheque Number":"","TranCode":"MB TRANSFER","ThirdPartyAccount":"123","Amount":"-20","formatedDate":"2013-07-29T12:00:00.000Z"}
{"Account":"789","Date":"2013-07-30","Unique Id":"2013073003","Tran Type":"CREDIT","Cheque Number":"","TranCode":"CREDIT","ThirdPartyAccount":"123","Amount":"20","formatedDate":"2013-07-29T12:00:00.000Z"}
{"Account":"789","Date":"2013-07-30","Unique Id":"2013073002","Tran Type":"TFR OUT","Cheque Number":"","TranCode":"MB TRANSFER","ThirdPartyAccount":"123","Amount":"-160","formatedDate":"2013-07-29T12:00:00.000Z"}
{"Account":"789","Date":"2013-07-30","Unique Id":"2013073001","Tran Type":"CREDIT","Cheque Number":"","TranCode":"CREDIT","ThirdPartyAccount":"123","Amount":"160","formatedDate":"2013-07-29T12:00:00.000Z"}
如果你确定维度的顺序没有改变和大量维度,那么你可以去json以下(注意:null不可接受)
{
"Account": [
789,
789,
789
],
"Date": [
"2013-07-31",
"2013-07-30",
"2013-07-31"
],
"Unique Id": [
2013073101,
2013073102,
2013073103
]
}
你可以从java客户端轻松解析它,每个索引适用于所有JSONArray,我选择几个键和值来显示我的JSON结构.
内容总结
以上是互联网集市为您收集整理的javascript – dc.js以json格式将维度数据发送到node.js服务器,然后使用java处理数据全部内容,希望文章能够帮你解决javascript – dc.js以json格式将维度数据发送到node.js服务器,然后使用java处理数据所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。