Package org.json

Examples of org.json.JSONException


        if (value instanceof JSONString) {
            Object o;
            try {
                o = ((JSONString) value).toJSONString();
            } catch (Exception e) {
                throw new JSONException(e);
            }
            if (o instanceof String) {
                return (String) o;
            }
            throw new JSONException("Bad value from toJSONString: " + o);
        }
        if (value instanceof Number) {
            return JSONObject.numberToString((Number) value);
        }
        if (value instanceof Boolean) {
View Full Code Here


        if (value instanceof JSONString) {
            Object object;
            try {
                object = ((JSONString)value).toJSONString();
            } catch (Exception e) {
                throw new JSONException(e);
            }
            if (object instanceof String) {
                return (String)object;
            }
            throw new JSONException("Bad value from toJSONString: " + object);
        }
        if (value instanceof Number) {
            return numberToString((Number) value);
        }
        if (value instanceof Boolean || value instanceof JSONObject ||
View Full Code Here

        return JSONObject.quote(value.toString());
    }

  static public String numberToString(Number number) throws Exception {
        if (number == null) {
            throw new JSONException("Null pointer");
        }
        testValidity(number);

// Shave off trailing zeros and decimal point, if possible.
View Full Code Here

  static public void testValidity(Object o) throws Exception {
        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.");
                }
            }
        }
    }
View Full Code Here

                    } else if (obj instanceof Number) {
                        return fromNumber((Number)obj, target);
                    } else if (obj instanceof String) {
                        return fromString((String)obj, target);
                    } else {
                        throw new JSONException("cannot convert " +
                            obj.getClass() + " to " + target);
                    }
                } else {
                    return obj;
                }
View Full Code Here

                } else {        
                    return obj == null? Boolean.FALSE : Boolean.TRUE;
                }
            }

            throw new JSONException("cannot convert " +
                        obj.getClass() + " to " + target);
        }
View Full Code Here

                throw makeJSONException(exp);
            }
        }

        private JSONException makeJSONException(Exception exp) {
            JSONException jexp = new JSONException(exp.toString());
            jexp.initCause(exp);
            return jexp;
        }
View Full Code Here

            }
            objectEnd(map);
        }

        private JSONException makeJSONException(Exception exp) {
            JSONException jexp = new JSONException(exp.toString());
            jexp.initCause(exp);
            return jexp;
        }
View Full Code Here

  {
    int last = fixup.length()-1;

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

    Object originalObject = traverse(arguments, original, false);
    Object fixupParent = traverse(arguments, 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 arr;
    }
    catch (Exception e)
    {
      log.error("unexpected exception",e);
      throw new JSONException("unexpected exception");
    }
  }
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.