轉JSONObject put,accumulate,element的區別

來源:互聯網
上載者:User

標籤:content   already   app   ppi   div   class   store   article   and   

  public Object put (Object key, Object value) 將value映射到key下。如果此JSONObject對象之前存在一個value在這個key下,當前的value會替換掉之前的valueAssociates the specified value with the specified key in this map(optional operation). If the map previously contained . a mapping for this key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true .)) public JSONObject accumulate (String key, Object value) 累積value到這個key下。這個方法同element()方法類似,特殊的是,如果當前已經存在一個value在這個key下那麼一個JSONArray將會儲存在這個key下來儲存所有累積的value。如果已經存在一個JSONArray,那麼當前的value就會添加到這個JSONArray中。相比之下replace方法會替代先前的valueAccumulate values under a key. It is similar to the element method except that if there is already an object stored under the key then a JSONArray is stored under the key to hold all of the accumulated values. If there is already a JSONArray, then the new value is appended to it. In contrast, the replace method replaces the previous value. public JSONObject element (String key, Object value) 將鍵/值對放到這個JSONObject對象裡面。如果當前value為空白(null),那麼如果這個key存在的話,這個key就會移除掉。如果這個key之前有value值,那麼此方法會調用accumulate()方法。Put a key/value pair in the JSONObject. If the value is null, then the key will be removed from the JSONObject if it is present. If there is a previous value assigned to the key, it will call accumulate.

轉JSONObject put,accumulate,element的區別

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.