简体   繁体   English

将java数据传递给json,然后从javascript获取数据

[英]pass java data into json and then get data from javascript

I was told that the way to send data from Java to JavaScript is to convert the Java data into JSon flat file and then read the file from JavaScript side. 有人告诉我,将数据从Java发送到JavaScript的方法是将Java数据转换为JSon平面文件,然后从JavaScript端读取文件。 I wonder if anyone could show me a simple example. 我想知道是否有人能给我一个简单的例子。 For example, in java, I have 例如,在java中,我有

ArrayList arrlist = new ArrayList(); ArrayList arrlist = new ArrayList();

arrlist.add("string1"); arrlist.add( “字符串1”);

arrlist.add("string2"); arrlist.add( “字符串2”);

arrlist.add("string3"); arrlist.add( “STRING3”);

arrlist.add("string4"); arrlist.add( “串,4”);

arrlist.add("string5"); arrlist.add( “STRING5”);

how could I really get the data in the arrlist from JavaScript side? 我怎样才能真正从JavaScript端获取arrlist中的数据?

Thank you in advance. 先感谢您。

要将列表的内容放入JSON,您可以使用

JSONArray arrListJson = new JSONArray(arrList);

For such purpose, it is really convenient to use a JSON library such as Jackson. 出于这个目的,使用像Jackson这样的JSON库非常方便。 Refer to this link for a quick start. 请参阅此链接以快速入门。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM