org.codehaus.jettison.json.JSONException.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(322)

本文整理了Java中org.codehaus.jettison.json.JSONException.<init>()方法的一些代码示例,展示了JSONException.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONException.<init>()方法的具体详情如下:
包路径:org.codehaus.jettison.json.JSONException
类名称:JSONException
方法名:<init>

JSONException.<init>介绍

[英]Constructs a JSONException with an explanatory message.
[中]构造带有解释性消息的JSONException。

代码示例

代码示例来源:origin: json-path/JsonPath

private Object parse(JettisonTokener JsonTokener)
{
  try
  {
    char nextChar = JsonTokener.nextClean();
    JsonTokener.back();
    if (nextChar == '{') 
    {
      return new JettisonObject(JsonTokener);
    }
    if (nextChar == '[') 
    {
      return new JettisonArray(JsonTokener);
    }
    throw new JSONException("Invalid JSON");
  }
  catch( org.codehaus.jettison.json.JSONException jsonException )
  {
    throw new IllegalStateException(jsonException);
  }
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Pop an array or object scope.
 * @param c The scope to close.
 * @throws JSONException If nesting is wrong.
 */
private void pop(char c) throws JSONException {
  if (this.top <= 0 || this.stack[this.top - 1] != c) {
    throw new JSONException("Nesting error.");
  }
  this.top -= 1;
  this.mode = this.top == 0 ? 'd' : this.stack[this.top - 1];
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Push an array or object scope.
 * @param c The scope to open.
 * @throws JSONException If nesting is too deep.
 */
private void push(char c) throws JSONException {
  if (this.top >= maxdepth) {
    throw new JSONException("Nesting too deep.");
  }
  this.stack[this.top] = c;
  this.mode = c;
  this.top += 1;
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Throw an exception if the object is an NaN or infinite number.
 * @param o The object to test.
 * @throws JSONException If o is a non-finite number.
 */
static void testValidity(Object o) throws JSONException {
  if (o != null) {
    if (o instanceof Double) {
      if (((Double)o).isInfinite() || ((Double)o).isNaN()) {
        throw new JSONException(
          "JSON does not allow non-finite numbers");
      }
    } else if (o instanceof Float) {
      if (((Float)o).isInfinite() || ((Float)o).isNaN()) {
        throw new JSONException(
          "JSON does not allow non-finite numbers.");
      }
    }
  }
}

代码示例来源:origin: org.codehaus.jettison/jettison

private double doGetDouble(String key, Object o) throws JSONException {
  try {
    return o instanceof Number ?
      ((Number)o).doubleValue() : 
      Double.valueOf((String)o).doubleValue();
  } catch (Exception e) {
    throw new JSONException("JSONObject[" + quote(key) +
      "] is not a number.");
  }
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * End something.
 * @param m Mode
 * @param c Closing character
 * @return this
 * @throws JSONException If unbalanced.
 */
private JSONWriter end(char m, char c) throws JSONException {
  if (this.mode != m) {
    throw new JSONException(m == 'o' ? "Misplaced endObject." :
      "Misplaced endArray.");
  }
  this.pop(m);
  try {
    this.writer.write(c);
  } catch (IOException e) {
    throw new JSONException(e);
  }
  this.comma = true;
  return this;
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Make a JSONException to signal a syntax error.
 *
 * @param message The error message.
 * @return  A JSONException object, suitable for throwing
 */
public JSONException syntaxError(String message) {
  return new JSONException(message + toString(), 0, myIndex);
}

代码示例来源:origin: org.codehaus.jettison/jettison

private boolean doGetBoolean(String key, Object o) throws JSONException {
  if (o.equals(Boolean.FALSE) ||
      (o instanceof String &&
      ((String)o).equalsIgnoreCase("false"))) {
    return false;
  } else if (o.equals(Boolean.TRUE) ||
      (o instanceof String &&
      ((String)o).equalsIgnoreCase("true"))) {
    return true;
  }
  throw new JSONException("JSONObject[" + quote(key) +
      "] is not a Boolean.");
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the object value associated with an index.
 * @param index
 *  The index must be between 0 and length() - 1.
 * @return An object value.
 * @throws JSONException If there is no value for the index.
 */
public Object get(int index) throws JSONException {
  Object o = opt(index);
  if (o == null) {
    throw new JSONException("JSONArray[" + index + "] not found.");
  }
  return o;
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the JSONArray associated with an index.
 * @param index The index must be between 0 and length() - 1.
 * @return      A JSONArray value.
 * @throws JSONException If there is no value for the index. or if the
 * value is not a JSONArray
 */
public JSONArray getJSONArray(int index) throws JSONException {
  Object o = get(index);
  if (o instanceof JSONArray) {
    return (JSONArray)o;
  }
  throw new JSONException("JSONArray[" + index +
      "] is not a JSONArray.");
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the JSONObject associated with an index.
 * @param index subscript
 * @return      A JSONObject value.
 * @throws JSONException If there is no value for the index or if the
 * value is not a JSONObject
 */
public JSONObject getJSONObject(int index) throws JSONException {
  Object o = get(index);
  if (o instanceof JSONObject) {
    return (JSONObject)o;
  }
  throw new JSONException("JSONArray[" + index +
    "] is not a JSONObject.");
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the double value associated with an index.
 *
 * @param index The index must be between 0 and length() - 1.
 * @return      The value.
 * @throws   JSONException If the key is not found or if the value cannot
 *  be converted to a number.
 */
public double getDouble(int index) throws JSONException {
  Object o = get(index);
  try {
    return o instanceof Number ?
      ((Number)o).doubleValue() : 
      Double.valueOf((String)o).doubleValue();
  } catch (Exception e) {
    throw new JSONException("JSONArray[" + index +
      "] is not a number.");
  }
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the boolean value associated with an index.
 * The string values "true" and "false" are converted to boolean.
 *
 * @param index The index must be between 0 and length() - 1.
 * @return      The truth.
 * @throws JSONException If there is no value for the index or if the
 *  value is not convertable to boolean.
 */
public boolean getBoolean(int index) throws JSONException {
  Object o = get(index);
  if (o.equals(Boolean.FALSE) ||
      (o instanceof String &&
      ((String)o).equalsIgnoreCase("false"))) {
    return false;
  } else if (o.equals(Boolean.TRUE) ||
      (o instanceof String &&
      ((String)o).equalsIgnoreCase("true"))) {
    return true;
  }
  throw new JSONException("JSONArray[" + index + "] is not a Boolean.");
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the value object associated with a key.
 *
 * @param key   A key string.
 * @return      The object associated with the key.
 * @throws   JSONException if the key is not found.
 */
public Object get(String key) throws JSONException {
  Object o = opt(key);
  if (o == null) {
    throw new JSONException("JSONObject[" + quote(key) +
        "] not found.");
  }
  return o;
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the JSONObject value associated with a key.
 *
 * @param key   A key string.
 * @return      A JSONObject which is the value.
 * @throws   JSONException if the key is not found or
 *  if the value is not a JSONObject.
 */
public JSONObject getJSONObject(String key) throws JSONException {
  Object o = get(key);
  if (o instanceof JSONObject) {
    return (JSONObject)o;
  }
  throw new JSONException("JSONObject[" + quote(key) +
      "] is not a JSONObject.");
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Get the JSONArray value associated with a key.
 *
 * @param key   A key string.
 * @return      A JSONArray which is the value.
 * @throws   JSONException if the key is not found or
 *  if the value is not a JSONArray.
 */
public JSONArray getJSONArray(String key) throws JSONException {
  Object o = get(key);
  if (o instanceof JSONArray) {
    return (JSONArray)o;
  }
  throw new JSONException("JSONObject[" + quote(key) +
      "] is not a JSONArray.");
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Begin appending a new array. All values until the balancing
 * <code>endArray</code> will be appended to this array. The
 * <code>endArray</code> method must be called to mark the array's end.kue
 * @return this
 * @throws JSONException If the nesting is too deep, or if the object is
 * started in the wrong place (for example as a key or after the end of the
 * outermost array or object).
 */
public JSONWriter array() throws JSONException {
  if (this.mode == 'i' || this.mode == 'o' || this.mode == 'a') {
    this.push('a');
    this.append("[");
    this.comma = false;
    return this;
  }
  throw new JSONException("Misplaced array.");
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Begin appending a new object. All keys and values until the balancing
 * <code>endObject</code> will be appended to this object. The
 * <code>endObject</code> method must be called to mark the object's end.
 * @return this
 * @throws JSONException If the nesting is too deep, or if the object is
 * started in the wrong place (for example as a key or after the end of the
 * outermost array or object).
 */
public JSONWriter object() throws JSONException {
  if (this.mode == 'i') {
    this.mode = 'o';
  }
  if (this.mode == 'o' || this.mode == 'a') {
    this.append("{");
    this.push('k');
    this.comma = false;
    return this;
  }
  throw new JSONException("Misplaced object.");
}

代码示例来源:origin: com.jayway.jsonpath/json-path

private Object parse(JettisonTokener JsonTokener)
{
  try
  {
    char nextChar = JsonTokener.nextClean();
    JsonTokener.back();
    if (nextChar == '{') 
    {
      return new JettisonObject(JsonTokener);
    }
    if (nextChar == '[') 
    {
      return new JettisonArray(JsonTokener);
    }
    throw new JSONException("Invalid JSON");
  }
  catch( org.codehaus.jettison.json.JSONException jsonException )
  {
    throw new IllegalStateException(jsonException);
  }
}

代码示例来源:origin: org.codehaus.jettison/jettison

/**
 * Append values to the array under a key. If the key does not exist in the
 * JSONObject, then the key is put in the JSONObject with its value being a
 * JSONArray containing the value parameter. If the key was already
 * associated with a JSONArray, then the value parameter is appended to it.
 * @param key   A key string.
 * @param value An object to be accumulated under the key.
 * @return this.
 * @throws JSONException If the key is null or if the current value 
 *  associated with the key is not a JSONArray.
 */
public JSONObject append(String key, Object value)
    throws JSONException {
  testValidity(value);
  Object o = opt(key);
  if (o == null) {
    put(key, new JSONArray().put(value));
  } else if (!(o instanceof JSONArray)){
    throw new JSONException("JSONObject[" + key + 
          "] is not a JSONArray.");
  } else {
    ((JSONArray)o).put(value);
  }
  return this;
}

相关文章