【问题标题】:Converting Map<Enum, Object> to JSON将 Map<Enum, Object> 转换为 JSON
【发布时间】:2015-02-18 19:39:41
【问题描述】:

我在这样的服务器上构建了一个 json:

List<Object> resp = new ArrayList<>();
for (String str : buffer.toString().split("\\n")) {
    for (String data : str.split("\\s")) {
        if (data.matches("[\\w|\\W]+") && !data.isEmpty()) {
            Child.set(Child.children, "null");
            Child.set(Child.parent, chain.name());
            Child.set(Child.name, data);
        }
        Child.setChild(Child.get());
    }
}

Child.set(Child.children, Child.getChild().toArray());
Child.set(Child.parent, "null");
Child.set(Child.name, chain.name());

问题是 Child 是 HashMap&lt;Child, Object&gt; 但是当我将 Child.set(Child.children, Child.getChild().toArray()); 放入 Map 然后将带有 Google Gson 的 Map 对象转换为 Json 时,它会因错误而中断:

oejw.WebSocketConnectionRFC6455:java.lang.StackOverflowError

我认为问题不在于WebSocket,因为当我之前将Child.getChild().toArray()转换为json然后将其放到地图上时,没有任何错误,但生成的json并没有完全纠正。

【问题讨论】:

    标签: java json dictionary gson


    【解决方案1】:

    问题在于转换为 Json。 Gson 转换时出现堆栈溢出错误。 使用 JSONObject 和 JSONArray 解决。

    【讨论】:

      猜你喜欢
      • 2015-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-24
      • 1970-01-01
      • 2013-05-24
      • 2014-01-29
      • 1970-01-01
      相关资源
      最近更新 更多