开发者

What's the proper representation of LinkedHashMap in JSON?

When I serialize my LinkedHashMap<String, String> using GSON, I get

{"b":"a","a":"1","c":"2"}

and after deserializing I get back the elements in the right or开发者_JAVA技巧der. So everything works fine, but is there a guarantee that every tool works this way? Does the order of entries have any significance in JSON?


No, Javascript hashes do not necessarily have a consistent order. For that, you'd probably want a representation like

[["b", "a"], ["a", "1"], ["c", "2"]]

or store the key order in a separate list, depending on what you are doing with it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜