(Java) JSON AppendArray2 Example
Demonstrates the AppendArray2 function. Note: This example requires Chilkat v11.0.0 or greater.
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[])
{
CkJsonObject json = new CkJsonObject();
json.Load("{ \"name\": \"John\", \"marbles\": 100 }");
// Append an empty array named "xyz"
CkJsonArray jarr = new CkJsonArray();
json.AppendArray2("xyz",jarr);
System.out.println(json.emit());
// Expected output is: {"name":"John","marbles":100,"xyz":[]}
// Add elements to the array.
jarr.AddStringAt(-1,"hello");
jarr.AddIntAt(-1,256);
System.out.println(json.emit());
// Expected output is: {"name":"John","marbles":100,"xyz":["hello",256]}
}
}
|