嘿,我想知道是否可以编辑现有的 json 我知道位置。
假设位置是 C:\Something.json
那我该如何编辑呢??
Thanks
如果你想编辑复杂的 JSON 结构,我建议使用GSON https://code.google.com/p/google-gson/图书馆。然后您可以执行以下步骤:
Gson gson = new Gson();
String yourfilecontents; //read contents from File
1)读取JSON文件并将其转换为对象结构。
YourObject obj = gson.fromJson(yourfilecontents, YourObject.class);
2)根据您的要求修改对象。
obj.field1(newValue);
3)将对象转换为JSON
String newJson = gson.toJson(obj);
4)将JSON(newJson)写回文件
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)