简体   繁体   中英

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. I wonder if anyone could show me a simple example. For example, in java, I have

ArrayList arrlist = new ArrayList();

arrlist.add("string1");

arrlist.add("string2");

arrlist.add("string3");

arrlist.add("string4");

arrlist.add("string5");

how could I really get the data in the arrlist from JavaScript side?

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. Refer to this link for a quick start.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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