Sample code for 30+ languages & platforms
Java

JSON AppendObject2 Example

Demonstrates the AppendObject2 function.

Chilkat Java Downloads

Java
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 = new CkJsonObject();
    json.AppendObject2("addr",jObj);

    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}}
  }
}