Java Requires Chilkat v11.4.0+
Chilkat2 Java
Example: JsonObject.NewArrayOf method
See more JSON Examples
Demonstrates theNewArrayOf method.
Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.JsonObject;
public class ChilkatExample {
public static void main(String[] args) {
String big_cats = "[\"lion\",\"tiger\",\"leopard\",\"jaguar\",\"cheetah\",\"snow leopard\",\"clouded leopard\",\"cougar\",\"puma\",\"panther\"]";
JsonObject json = new JsonObject();
json.updateString("test", "abc");
try {
json.newArrayOf("big_cats", big_cats);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
json.setEmitCompact(false);
System.out.println(json.emit());
// Result:
// {
// "test": "abc",
// "big_cats": [
// "lion",
// "tiger",
// "leopard",
// "jaguar",
// "cheetah",
// "snow leopard",
// "clouded leopard",
// "cougar",
// "puma",
// "panther"
// ]
// }
}
}