0

我正在开发一个 GWT 应用程序。

我想将 hashMap 转换为 JSON 字符串并将其发送到 GWT 服务器

我的 HashMap 就像HashMap<String, CustomProperties)

CustomProperties 是具有不同参数的类。此 HashMap 是 file 的属性。

我想上传具有这些属性的文件。

我要做什么:将 json Sting 附加到隐藏字段并通过 formPanel 将其与文件一起发送。

但我不知道如何将 Hashmap 转换为 JSON 字符串。

任何人都可以在这方面指导我吗?

4

3 回答 3

0

考虑使用GWT AutoBean框架与 JSON 进行序列化。

于 2012-08-30T17:22:34.990 回答
0

JohnS 的回答很有道理。但是,有一个相关且很久以前回答的问题:GWT HashMap to/from JSON了解详细信息。

于 2012-08-30T18:52:47.127 回答
0

你可以试试杰克逊。

http://wiki.fasterxml.com/JacksonInFiveMinutes

ObjectMapper mapper = new ObjectMapper(); 
mapper.writeValue(outputStream, yourMap);
yourMapinJson=outputStream.toString();
于 2012-08-31T08:14:26.140 回答