Package org.json

Examples of org.json.JSONException


            Object value;
            try {
                value = JSONObject.stringToValue(new String(bytes, 0, length,
                        "US-ASCII"));
            } catch (UnsupportedEncodingException e) {
                throw new JSONException(e);
            }
            this.values.register(value);
            return value;
        case 2:
            return getAndTick(this.values, this.bitreader);
        case 3:
            return readJSON();
        default:
            throw new JSONException("Impossible.");
        }
    }
View Full Code Here


            if (JSONzip.probe) {
                JSONzip.logchar(symbol.integer, this.width);
            }
            return symbol.integer;
        } catch (Throwable e) {
            throw new JSONException(e);
        }
    }
View Full Code Here

                } else {
                    bitwriter.one();
                }
            }
        } catch (Throwable e) {
            throw new JSONException(e);
        }
    }
View Full Code Here

  public void testDoGetWithHandlerJsonException() throws Exception {
    HttpServletRequest request = createGetRequest("{\"gadgets\":[]}", "function");
    HttpServletResponse response = createHttpResponse("Malformed JSON request.",
        HttpServletResponse.SC_BAD_REQUEST);
    expect(handler.process(isA(JSONObject.class))).andThrow(new JSONException("json"));
    replay(handler);
    servlet.doGet(request, response);
    verify(response);
  }
View Full Code Here

    public static void applyFixup(final Object object, final JSONArray fixup,
            final JSONArray original) throws JSONException {
        int last = fixup.length() - 1;

        if (last < 0) {
            throw new JSONException("fixup path must contain at least 1 reference");
        }

        final Object originalObject = traverse(object, original, false);
        final Object fixupParent = traverse(object, fixup, true);

        // the last ref in the fixup needs to be created
        // it will be either a string or number depending on if the fixupParent is a
        // JSONObject or JSONArray

        if (fixupParent instanceof JSONObject) {
            String objRef = fixup.optString(last, null);
            if (objRef == null) {
                throw new JSONException("last fixup reference not a string");
            }
            ((JSONObject) fixupParent).put(objRef, originalObject);
        } else {
            int arrRef = fixup.optInt(last, -1);
            if (arrRef == -1) {
                throw new JSONException("last fixup reference not a valid array index");
            }
            ((JSONArray) fixupParent).put(arrRef, originalObject);
        }
    }
View Full Code Here

                return obj;
            }
            return arr;
        } catch (Exception e) {
            logger.log(Level.SEVERE, "unexpected exception", e);
            throw new JSONException("unexpected exception");
        }
    }
View Full Code Here

     * @throws JSONException if something goes wrong.
     */
    private static Object next(final Object prev,
            final String ref) throws JSONException {
        if (prev == null) {
            throw new JSONException("cannot traverse- missing object encountered");
        }
        if (prev instanceof JSONObject) {
            return ((JSONObject) prev).get(ref);
        }
        throw new JSONException("not an object");
    }
View Full Code Here

     * @throws JSONException if something goes wrong.
     */
    private static Object next(final Object prev,
            int idx) throws JSONException {
        if (prev == null) {
            throw new JSONException("cannot traverse- missing object encountered");
        }

        if (prev instanceof JSONArray) {
            return ((JSONArray) prev).get(idx);
        }
        throw new JSONException("not an array");
    }
View Full Code Here

        return this.db;
    }
    try  {
      db = constructJSONObjFromDB();
    } catch (Exception e) {
      throw new JSONException("Cannot construct JSON object from database." +
          e.getMessage());
    }
    lastUpdatedTime = now;
    return db;
  }
View Full Code Here

            }
        } else if (this.jsonRepresentation != null) {
            try {
                result = this.jsonRepresentation.getText();
            } catch (IOException e) {
                throw new JSONException(e);
            }
        }

        return result;
    }
View Full Code Here

TOP

Related Classes of org.json.JSONException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.