【问题标题】:JSONSerializer.toJSON ignores key 'class'JSONSerializer.toJSON 忽略键 \'class\'
【发布时间】:2022-11-24 01:23:14
【问题描述】:

如果 JSON 字符串包含“类”键,如何使用 JSONSerializer 将 JSON 字符串转换为 JSON?通过使用 toJSON 方法,所有“类”键都将被忽略:

String str = "{'test': 'ok', 'class' : 'fail'}";
JSON json = JSONSerializer.toJSON(str) // result is: {"test":"ok"}

【问题讨论】:

    标签: java jsonserializer


    【解决方案1】:

    我找到了:

    JsonConfig cfg = new JsonConfig();
    cfg.setIgnoreDefaultExcludes(true);
    
    JSON json = JSONSerializer.toJSON(str, cfg) // {"test":"ok", "class":"fail"}
    

    【讨论】:

      猜你喜欢
      • 2011-10-20
      • 2020-01-30
      • 2021-12-27
      • 1970-01-01
      • 1970-01-01
      • 2014-10-05
      • 1970-01-01
      • 2020-08-30
      • 1970-01-01
      相关资源
      最近更新 更多