JSON.simple - Hợp nhất Mảng

Trong JSON.simple, chúng ta có thể hợp nhất hai Mảng JSON một cách dễ dàng bằng cách sử dụng phương thức JSONArray.addAll ().

Ví dụ sau minh họa khái niệm trên.

Thí dụ

import java.io.IOException;
import org.json.simple.JSONArray;

class JsonDemo {
   public static void main(String[] args) throws IOException {
      JSONArray list1 = new JSONArray();
      list1.add("foo");
      list1.add(new Integer(100));

      JSONArray list2 = new JSONArray();       
      list2.add(new Double(1000.21));
      list2.add(new Boolean(true));
      list2.add(null);

      list1.addAll(list2);       
      System.out.println(list1);       
   }
}

Đầu ra

["foo",100,1000.21,true,null]