Merge JSON Array
JSON Simple is a java library for encoding and decoding JSON text.
Get the latest binaries from
http://code.google.com/p/json-simple/ .
The following example shows merging two JSON Arrays.
package com.bethecoder.tutorials.json_simple.tests;
import java.io.IOException;
import org.json.simple.JSONArray;
public class MergeJsonArrays {
/**
* @param args
* @throws IOException
*/
public static void main ( String [] args ) throws IOException {
JSONArray jsonArray = new JSONArray () ;
jsonArray.add ( "one" ) ;
jsonArray.add ( "two" ) ;
jsonArray.add ( "three" ) ;
JSONArray jsonArray2 = new JSONArray () ;
jsonArray2.add ( "three" ) ;
jsonArray2.add ( "four" ) ;
jsonArray.addAll ( jsonArray2 ) ;
System.out.println ( jsonArray ) ;
}
}
It gives the following output,
["one","two","three","three","four"]