Java Requires Chilkat v11.0.0+
Chilkat2 Java
JSON AppendObject2 Example
Demonstrates the AppendObject2 function.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.JsonObject;
public class ChilkatExample {
public static void main(String[] args) {
JsonObject json = new JsonObject();
json.load("{ \"name\": \"John\", \"marbles\": 100 }");
// Append an empty object named "addr"
JsonObject jObj = new JsonObject();
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}}
}
}