English 中文(简体)
JSON.simple - Merging Arrays
  • 时间:2024-12-22

JSON.simple - Merging Arrays


Previous Page Next Page  

In JSON.simple, we can merge two JSON Arrays easily using JSONArray.addAll() method.

Following example illustrates the above concept.

Example

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

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

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

      pst1.addAll(pst2);       
      System.out.println(pst1);       
   }
}

Output

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