Java
Java
Copy JSON Object from one JSON Array to Another
See more JSON Examples
Demonstrates how to copy an object in a JSON array to another JSON array.Chilkat Java Downloads
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
CkJsonArray arr1 = new CkJsonArray();
CkJsonArray arr2 = new CkJsonArray();
String s = "[{\"a\":1}, {\"b\":2}, {\"c\":3}]";
String sEmpty = "[]";
arr1.Load(s);
arr2.Load(sEmpty);
CkJsonObject jObj = new CkJsonObject();
arr1.ObjectAt2(1,jObj);
arr2.AddObjectCopyAt(-1,jObj);
System.out.println(arr2.emit());
// output is: [{"b":2}]
}
}