本文介绍了如何更改json对象名称(键)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只是一个简单的问题:
如果我有一个包含key / value的json对象:
If I have a json object which contains "key/value"s like this:
"name":"value"
我想将名称部分更改为其他内容,我该怎么办?我不想删除并重新创建它。
and I want to change the name parts to something else, what should I do? I don't want to remove and make it again.
推荐答案
正确而紧凑的实现,假设 jsonObject
是您引用的json对象,它是 JSONObject
的实例:
Proper and compact implementation, given that jsonObject
is the json object you are referring to and it is an instance of JSONObject
:
jsonObject.put("new name", jsonObject.remove("name"));
这篇关于如何更改json对象名称(键)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!