【20004】Java常用方法

  • 格式化JSON
public static void main(String[] args) {
    String text = "{\"hello\":{\"test\":\"val\"}}";
    String pretty = JSON.toJSONString(JSON.parseObject(text), SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue,
            SerializerFeature.WriteDateUseDateFormat);
    System.out.println(pretty);
}
{
    "hello":{
        "test":"val"
    }
}

你可能感兴趣的:(【20004】Java常用方法)