在我的服务包中,我返回一个linkedHashMap,并在 Controller 中将其转换为JSON,例如:
JSONObject jsonObject = new JSONObject();
jsonObject.put("dataObject", JSONObject.fromObject(linkedHashMap));
return jsonObject.toString();
为什么将linkedHashMap转换为JSON时顺序会困惑?
最佳答案
您不能对 JSON 对象中的元素进行排序。
来自 http://www.json.org/ 的 JSON 规范
An object is an unordered set of name/value pairs
关于java - JSON 处理linkedHashMap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19264808/