Sample code for 30+ languages & platforms
Java

Get JSON Details from the Last REST Operation

See more REST Examples

Demonstrates Rest.GetLastJsonData, which copies operation-specific diagnostic or result information from the most recently completed method into a JsonObject. Many methods produce no JSON, in which case the object is empty.

Tip: Code to parse the returned JSON can be generated with Chilkat's online tool at https://tools.chilkat.io/jsonParse.

Background. Some Chilkat operations expose additional structured information as JSON. GetLastJsonData provides access to that information after an operation completes.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.Rest;

public class ChilkatExample {

    public static void main(String[] args) {
        Rest rest = new Rest();
        boolean bTls = true;
        boolean bAutoReconnect = true;
        try {
            rest.connect("example.com", 443, bTls, bAutoReconnect);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // Copy operation-specific diagnostic or result information from the most recent method (here the
        // Connect call) into a JsonObject.  Many methods produce no JSON, in which case the object is empty.
        JsonObject json = new JsonObject();
        rest.getLastJsonData(json);

        json.setEmitCompact(false);
        String jsonStr = json.emit();
        System.out.println(jsonStr);
        // JSON parsing code for this result can be generated at Chilkat's online tool:
        // https://tools.chilkat.io/jsonParse
    }
}