Sample code for 30+ languages & platforms
Java

Load a JSON Array

See more JSON Examples

The Chilkat JSON API requires the top-level JSON to be an object. Therefore, to load an array requires that it first be wrapped as an object.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.JsonArray;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.StringBuilder;

public class ChilkatExample {

    public static void main(String[] args) {
        // Imagine we want to load this JSON array for parsing:
        String jsonArrayStr = "[{\"id\":200},{\"id\":196}]";

        // First wrap it in a JSON object by prepending "{ "array":" and appending "}"
        StringBuilder sbJson = new StringBuilder();
        sbJson.append("{\"array\":");
        sbJson.append(jsonArrayStr);
        sbJson.append("}");

        JsonObject json = new JsonObject();
        json.load(sbJson.getAsString());

        // Now we can get the JSON array
        JsonArray jArray = json.arrayAt(0);

        // Do what you want with the JSON array...
        // For example:
        JsonObject jObjId = jArray.objectAt(0);
        System.out.println(jObjId.intOf("id"));
        jObjId.close();

        jArray.close();
    }
}