Example usage for org.json JSONTokener skipPast

List of usage examples for org.json JSONTokener skipPast

Introduction

In this page you can find the example usage for org.json JSONTokener skipPast.

Prototype

public boolean skipPast(String to) 

Source Link

Document

Skip characters until past the requested string.

Usage

From source file:com.auth0.api.internal.ApplicationInfoRequest.java

@Override
public void onResponse(Response response) throws IOException {
    if (!response.isSuccessful()) {
        String message = "Received app info failed response with code " + response.code() + " and body "
                + response.body().string();
        postOnFailure(new IOException(message));
        return;/*w w w. j  a v  a 2s  .c  o  m*/
    }
    try {
        String json = response.body().string();
        JSONTokener tokenizer = new JSONTokener(json);
        tokenizer.skipPast("Auth0.setClient(");
        if (!tokenizer.more()) {
            postOnFailure(tokenizer.syntaxError("Invalid App Info JSONP"));
            return;
        }
        Object nextValue = tokenizer.nextValue();
        if (!(nextValue instanceof JSONObject)) {
            tokenizer.back();
            postOnFailure(tokenizer.syntaxError("Invalid JSON value of App Info"));
        }
        JSONObject jsonObject = (JSONObject) nextValue;
        Log.d(TAG, "Obtained JSON object from JSONP: " + jsonObject);
        Application app = getReader().readValue(jsonObject.toString());
        postOnSuccess(app);
    } catch (JSONException | IOException e) {
        postOnFailure(new APIClientException("Failed to parse JSONP", e));
    }
}