(Java) JSON AppendObject Example
Demonstrates the AppendObject function.
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 object named "addr"
CkJsonObject jObj = json.AppendObject("addr");
System.out.println(json.emit());
// Expected output is: {"name":"John","marbles":100,"addr":{}}
// Add members to the object.
jObj.AppendString("street","1200 Elm St.");
jObj.AppendString("city","Springfield");
jObj.AppendInt("zip",60606);
System.out.println(json.emit());
// Expected output is: {"name":"John","marbles":100,"addr":{"street":"1200 Elm St.","city":"Springfield","zip":60606}}
}
}
|