如何在java中更新现有的JSON文件
这是我的Json示例
{
"State": {
"version": "1",
"SName": "Test",
"shippingDetails": {
"Address1": "AP",
"ZipCode": "1236"
},
"Directions": {
"routes": [
{
"taxAmount": "0.0",
"Quantity": "5",
"bounds": {
"SerialVersion": [
{
"text": "1.7 km",
"value": "1729",
"time": "02633"
},
{
"text": "1.9 km",
"value": "1829",
"time": "02353"
},
{
"text": "17 km",
"value": "1059",
"time": "02133"
}
]
}
}
]
}
}
}
我想更新SName、ZipCode、taxAmount、Quantity和text[1]值 有没有办法做到这一点。我将JSON放在一个文件中,更新标记放在HashMap中
# 1 楼答案
put(...)
将用新值替换当前值。类似地,您可以更新其他值。完成后,可以使用以下方法将其转换回:并将其写回文件