使用JSON的Javascript到Java [英] Javascript to Java using JSON

查看:109
本文介绍了使用JSON的Javascript到Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划通过在JSON中编码来发送填充数据的Javascript数组对象。有什么好的jquery插件吗?

I am planning to send Javascript array object filled with data by encoding it in JSON. Any good jquery plugins for this ?

在Java端,将JSON解析为Java数组的标准方法是什么?

On Java end, what is the standard way of parsing the JSON into a Java array ?

整体流程如下:


  1. Javascript在当前页面上编译大量数据并将其存储在数组中。

  2. 编码为JSON的数组对象。

  3. Java代码保存JSON。

  4. 重复和Java代码编译成功每页的JSON。

  5. Java代码向服务器提交一个大型JSON。

  1. Javascript compiles bunch of data on current page and stores it in array.
  2. Array object encoded into JSON.
  3. Java code saves JSON.
  4. Repeat and Java code compiles succesive JSONs for each page.
  5. Java code submits one mega JSON to server.

另一个问题我有5.你如何安全地向服务器提交大型JSON数据?

Another problem I have is with 5. How would you go about submitting large JSON data to the server securely ?

推荐答案

在客户端,如果您只支持现代浏览器,则可以使用本机JSON.stringify()API。否则,json2.js库就可以了。

On the client-side, if you support only modern browsers, you can use the native JSON.stringify() API. Otherwise, the json2.js library is fine.

在服务器端,有一大堆库可供查看:

On the server-side, there are a herd of libraries to have a look at:

  • Jackson
  • json-lib
  • gson
  • and many more Java JSON libraries...

我首先指的是杰克逊,在很多情况下似乎是最快的。但是,每当我需要回到它时,我发现它的文档更难以解决。对于不需要最高速度但仍具有完全可接受的结果的较小任务,Json-lib有时更容易掌握。
Gson也是一个良好的声誉,而且非常灵活,但我之前发现的基准测试似乎表明它的表现不如杰克逊。新发布的1.5版本可能已经改进了,但我不知道。

I'm pointing you to Jackson first at it seems to be the fastest in many cases. However, I find its documentation harder to get my mind around every time I need to get back to it. Json-lib is sometimes easier to get to grasp with for smaller tasks that do not require top-speed, but with still completely acceptable results. Gson as also a good reputation and is very flexible, however the previous benchmarks I came across seemed to indicate that it did not perform as well as Jackson. The newly released 1.5 version might have improved that, but I don't know.

这取决于你想要的灵活程度,你需要的性能,以及是否你想要一个简单的API,或者你不介意一个更复杂的API。

It comes down to the degree of flexibility you want, the performance you need, and whether you want a simple API or if you don't mind a more complex one.

关于安全性,我认为你最好的选择是支持连接的SSL。否则你只需使用基于JS的加密就可以让窃听者变得更难,但这并不能保护你太多。为此寻找SJCL(斯坦福Javascript加密库)。

Regarding security, I think your best option here would be to support SSL for the connections. Otherwise you could just make things harder for eavesdroppers by simply using JS-based encryption, but that won't protect you too much. Look for SJCL (Stanford Javascript Crypto Library) for this.

这篇关于使用JSON的Javascript到Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆