List of usage examples for org.json JSONException JSONException
public JSONException(Throwable t)
From source file:cn.xdf.thinkutils.http2.JsonHttpResponseHandler.java
protected void handleSuccessJsonMessage(int statusCode, Header[] headers, Object jsonResponse) { if (jsonResponse instanceof JSONObject) { onSuccess(statusCode, headers, (JSONObject) jsonResponse); } else if (jsonResponse instanceof JSONArray) { onSuccess(statusCode, headers, (JSONArray) jsonResponse); } else {/*from w w w . j av a 2 s.c o m*/ onFailure(new JSONException("Unexpected type " + jsonResponse.getClass().getName()), (JSONObject) null); } }
From source file:game.Clue.JSONTokener.java
/** * Back up one character. This provides a sort of lookahead capability, * so that you can test for a digit or letter before attempting to parse * the next number or identifier./*from w w w .j av a2s . c om*/ */ public void back() throws JSONException { if (this.usePrevious || this.index <= 0) { throw new JSONException("Stepping back two steps is not supported"); } this.index -= 1; this.character -= 1; this.usePrevious = true; this.eof = false; }
From source file:game.Clue.JSONTokener.java
/** * Get the next character in the source string. * * @return The next character, or 0 if past the end of the source string. *///from ww w.j a va2 s. c o m public char next() throws JSONException { int c; if (this.usePrevious) { this.usePrevious = false; c = this.previous; } else { try { c = this.reader.read(); } catch (IOException exception) { throw new JSONException(exception); } if (c <= 0) { // End of stream this.eof = true; c = 0; } } this.index += 1; if (this.previous == '\r') { this.line += 1; this.character = c == '\n' ? 0 : 1; } else if (c == '\n') { this.line += 1; this.character = 0; } else { this.character += 1; } this.previous = (char) c; return this.previous; }
From source file:game.Clue.JSONTokener.java
/** * Skip characters until the next character is the requested character. * If the requested character is not found, no characters are skipped. * @param to A character to skip to./*from w ww . j av a 2 s.c o m*/ * @return The requested character, or zero if the requested character * is not found. */ public char skipTo(char to) throws JSONException { char c; try { long startIndex = this.index; long startCharacter = this.character; long startLine = this.line; this.reader.mark(1000000); do { c = this.next(); if (c == 0) { this.reader.reset(); this.index = startIndex; this.character = startCharacter; this.line = startLine; return c; } } while (c != to); } catch (IOException exception) { throw new JSONException(exception); } this.back(); return c; }
From source file:game.Clue.JSONTokener.java
/** * Make a JSONException to signal a syntax error. * * @param message The error message.//from w w w . j a va 2 s . c o m * @return A JSONException object, suitable for throwing */ public JSONException syntaxError(String message) { return new JSONException(message + this.toString()); }
From source file:org.cfr.restlet.ext.shindig.resource.RpcResourceTest.java
@Test public void testDoGetWithHandlerJsonException() throws Exception { Request request = createGetRequest("{\"gadgets\":[]}", "function"); Response response = createResponse(request, "Malformed JSON request.", Status.CLIENT_ERROR_BAD_REQUEST); expect(handler.process(isA(JSONObject.class))).andThrow(new JSONException("json")); replay(handler);/*www . j av a2 s . c o m*/ resource.init(Context.getCurrent(), request, response); resource.doGet(); // verify(response); }
From source file:com.fdwills.external.http.JsonHttpResponseHandler.java
@Override public final void onSuccess(final int statusCode, final Header[] headers, final byte[] responseBytes) { if (statusCode != HttpStatus.SC_NO_CONTENT) { Runnable parser = new Runnable() { @Override//from w w w . ja v a 2 s . c om public void run() { try { final Object jsonResponse = parseResponse(responseBytes); postRunnable(new Runnable() { @Override public void run() { if (jsonResponse instanceof JSONObject) { onSuccess(statusCode, headers, (JSONObject) jsonResponse); } else if (jsonResponse instanceof JSONArray) { onSuccess(statusCode, headers, (JSONArray) jsonResponse); } else if (jsonResponse instanceof String) { onFailure(statusCode, headers, (String) jsonResponse, new JSONException("Response cannot be parsed as JSON data")); } else { onFailure(statusCode, headers, new JSONException( "Unexpected response type " + jsonResponse.getClass().getName()), (JSONObject) null); } } }); } catch (final JSONException ex) { postRunnable(new Runnable() { @Override public void run() { onFailure(statusCode, headers, ex, (JSONObject) null); } }); } } }; if (!getUseSynchronousMode()) { new Thread(parser).start(); } else { // In synchronous mode everything should be run on one thread parser.run(); } } else { onSuccess(statusCode, headers, new JSONObject()); } }
From source file:com.fdwills.external.http.JsonHttpResponseHandler.java
@Override public final void onFailure(final int statusCode, final Header[] headers, final byte[] responseBytes, final Throwable throwable) { if (responseBytes != null) { Runnable parser = new Runnable() { @Override/* ww w . j a v a2 s . co m*/ public void run() { try { final Object jsonResponse = parseResponse(responseBytes); postRunnable(new Runnable() { @Override public void run() { if (jsonResponse instanceof JSONObject) { onFailure(statusCode, headers, throwable, (JSONObject) jsonResponse); } else if (jsonResponse instanceof JSONArray) { onFailure(statusCode, headers, throwable, (JSONArray) jsonResponse); } else if (jsonResponse instanceof String) { onFailure(statusCode, headers, (String) jsonResponse, throwable); } else { onFailure(statusCode, headers, new JSONException( "Unexpected response type " + jsonResponse.getClass().getName()), (JSONObject) null); } } }); } catch (final JSONException ex) { postRunnable(new Runnable() { @Override public void run() { onFailure(statusCode, headers, ex, (JSONObject) null); } }); } } }; if (!getUseSynchronousMode()) { new Thread(parser).start(); } else { // In synchronous mode everything should be run on one thread parser.run(); } } else { Log.v(LOG_TAG, "response body is null, calling onFailure(Throwable, JSONObject)"); onFailure(statusCode, headers, throwable, (JSONObject) null); } }
From source file:com.appjma.appdeployer.service.Parser.java
private Date getTimeOrThrow(JSONObject json, String key) throws JSONException { String time = JSONHelper.getStrinOrNull(json, key); try {/*from w w w. j a va 2s.co m*/ return mDateFormat.parse(time); } catch (ParseException e) { throw new JSONException("Could not parse time field \"" + key + "\" because: " + e.getMessage()); } }
From source file:nz.ac.otago.psyanlab.common.util.FileUtils.java
/** * Load PALE definition from deflated file. * //from w w w.j ava 2 s . c o m * @param paleFile Deflated PALE file. * @return Experiment definition. * @throws IOException * @throws JSONException */ public static Experiment loadExperimentDefinitionFromArchive(File paleFile) throws IOException, JSONException { String paleDefinition = new String(FileUtils.extractJust("experiment.json", paleFile)); if (TextUtils.isEmpty(paleDefinition)) { throw new IllegalStateException("PALE definition was empty."); } try { return ModelUtils.readDefinition(paleDefinition); } catch (RuntimeException e) { throw new JSONException("Failed to parse PALE definition."); } }