org.json.jsonobject:Java中的JSON KEYS嵌套和列出的JSON键
我试图在JSON对象中重命名密钥名称。我可以在顶级重命名,但如果在另一个对象内部存在的密钥或列表对象中是否存在,则无法重命名。
这是我到目前为止尝试的。
try {
jsonObject.put(value, jsonObject.remove(key));
LOG.trace("Renaming Field {} with Field {}", key, value);
} catch (JSONException e) {
throw new RuntimeException(e);
}
这是一个示例对象。
{
"id": 123,
"contactInformation": {
"contact": {
"email": "[email protected]",
}
},
"supportingCustomer": [
{
"supportingCustomerName": "JOHN"
},
{
"supportingCustomerName": "JOHN"
}
]
}
在这里,我可以重命名ID,但是很难重命名supportingCustomerName
以及contactInformation.contact.email
使用org.json.jsonobject
?还是还有其他图书馆,我可以用来重命名密钥。任何帮助都会不胜感激?
我的JSON和KEY没有固定。
I am trying to rename key names in a json object.I can rename at the top level, but unable to rename if the key present inside another object or if it present in a List Object.
This is what i have tried so far.
try {
jsonObject.put(value, jsonObject.remove(key));
LOG.trace("Renaming Field {} with Field {}", key, value);
} catch (JSONException e) {
throw new RuntimeException(e);
}
Here is an Example Object.
{
"id": 123,
"contactInformation": {
"contact": {
"email": "[email protected]",
}
},
"supportingCustomer": [
{
"supportingCustomerName": "JOHN"
},
{
"supportingCustomerName": "JOHN"
}
]
}
Here I can rename Id, but having difficulty renaming supportingCustomerName
and also contactInformation.contact.email
using org.json.JSONObject
? Or is there any other library, i can use to rename keys.Any Help would be appreciated?
My JSON And key are dynamic not fixated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于最终使用了
Finally Ended Up using