Java中JSONObject的accumulate()方法的重要性?
一个JSONObject的 是一种的无序集合名称 和值 对。的几个重要的方法JSONArray 是累加(),,put(),,opt()append()write()和等累加()方法累积的关键,并且此方法类似于下的值放()方法除外,如果有一个键下保存然后现有对象JSONArray可以存储在一个键下,以保存所有累积值。如果存在现有的JSONArray,则可以添加一个新值。
语法
public JSONObject accumulate(java.lang.String key, java.lang.Object value) throws JSONException
示例
import org.json.*;
public class JSONAccumulateMethodTest {
public static void main(String[] args) throws JSONException {
JSONObject jsonObj = new JSONObject();
jsonObj.accumulate("Technology", "Java");
jsonObj.accumulate("Technology", "Python");
jsonObj.accumulate("Technology", "Spark");
jsonObj.accumulate("Technology", "Selenium");
jsonObj.accumulate("Technology", ".Net");
System.out.println(jsonObj.toString(3));
}
}输出结果
{"Technology": [
"Java",
"Python",
"Spark",
"Selenium",
".Net"
]}