How to edit, modify nested JSONObject

前端 未结 4 1651
野趣味
野趣味 2021-02-14 21:29

Could you help me with this issue please. for example I have JSONEObject

{
\"glossary\": {
    \"title\": \"example glossary\",
    \"GlossDiv\": {
        \"ti         


        
4条回答
  •  无人共我
    2021-02-14 22:13

    You don't need to remove before calling put. JSONObject#put will replace any existing value. Simply call

    js.getJSONObject("glossary").getJSONObject("GlossDiv").put("seeds", "555");
    

    But how to get to wanted key for one step?

    You don't. You have a nested object tree. You must go through the full tree to reach your element. There might be a library out there that does this for you, but underneath it all, it will be traversing everything.

提交回复
热议问题