java - 通过正则表达式删除空键
问题描述
我正在尝试删除某些键的空值,我尝试使用此 REGEX 但它不起作用。请你的建议...
private static final String REMOVE_NULL_VALS_REGEX = ",\"([^\"]+)\":null|\"([^\"]+)\":null,|\"([^\"]+)\":null";
{
"event": "111e0d4a",
"type": "business",
"eventProducerId": "Billing",
"eventVersion": "1.0",
"headerReference": {
"activityId": "999",
},
"payload": {
"trans": "Line",
"details": {
"plan": {
"features": [
{
"featureName": "GSM",
}
],
"planName": "null"
},
"number": {
"mobileNumber": "111111111"
},
"lineType": "GSM"
},
"dea": "0000002",
"sourceBan": "null",
"financialAccount": {
"financialAccountNumber": "212121"
},
"reasonCode": "null"
}
}
我做了转换为字符串,我试图用正则表达式删除那些空值。
解决方案
我推荐你使用 GSON,非常简单的库
您可以使用此页面创建 pojo:http: //www.jsonschema2pojo.org/
你可以创建一个pojo(java类)
如果某个值为 null 则该类的值为 null 。
如果您想查看教程,可以查看以下链接:https ://www.mkyong.com/java/how-do-convert-java-object-to-from-json-format-gson-api/
推荐阅读
- firebase - 如何使用 Firebase 修复 Android Studio 自动完成?
- javascript - Formik 验证 isSubmitting / isValidating 未设置为 true
- javascript - 有没有办法同时用多个回调修改相同的状态?
- java - java.lang.ClassNotFoundException: org.apache.http.HttpEntity 在 HttpPost
- spring-boot - spring boot 无法解析 thymeleaf 模板
- sql-server - 将数据从 Excel 上传到 SQL 格式化日期
- sequelize.js - Sequelize:将 where 子句应用于子查询
- powershell - Invoke-PnPQuery 权限问题
- java - Android游戏在线,如何与远程数据库通信
- botframework - 将变量从网络聊天客户端传递到机器人框架