使用 json 模板文件创建新的 json 文件
我有一个 json 模板文件。使用 java 程序,我需要读取模板并使用更新的值创建一个新的 json 文件。
示例模板 json 示例:
{
"page": 2,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": [
{
"id": 7,
"email": "[email protected]",
"first_name": "Michael",
"last_name": "Lawson",
"avatar": "https://reqres.in/img/faces/7-image.jpg"
}
],
"support": {
"url": "https://reqres.in/#support-heading",
"text": "To keep ReqRes free, contributions towards server costs are appreciated!"
}
}
预期输出 json 文件:(更新的页面、名字、姓氏、电子邮件、文本)
{
"page": 3,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": [
{
"id": 7,
"email": "[email protected]",
"first_name": "MichaelPatric",
"last_name": "lastName",
"avatar": "https://reqres.in/img/faces/7-image.jpg"
}
],
"support": {
"url": "https://reqres.in/#support-heading",
"text": "text udpated"
}
}
需要一个通用的 java 代码/逻辑,使用它我们可以修改模板 json 中的任何值并创建新的输出 json 文件。 提前致谢!
I have a json template file. Using java program, I need to read the template and create a new json file with updated values.
Example Template json example:
{
"page": 2,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": [
{
"id": 7,
"email": "[email protected]",
"first_name": "Michael",
"last_name": "Lawson",
"avatar": "https://reqres.in/img/faces/7-image.jpg"
}
],
"support": {
"url": "https://reqres.in/#support-heading",
"text": "To keep ReqRes free, contributions towards server costs are appreciated!"
}
}
Expected output json file: (updated page,first name, last name, email, text)
{
"page": 3,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": [
{
"id": 7,
"email": "[email protected]",
"first_name": "MichaelPatric",
"last_name": "lastName",
"avatar": "https://reqres.in/img/faces/7-image.jpg"
}
],
"support": {
"url": "https://reqres.in/#support-heading",
"text": "text udpated"
}
}
Need a generic java code/logic using which we can modify any values from template json and create new output json file.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论