Package org.json

Examples of org.json.JSONException


  @Test
  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


    try {
      log.fine(String.format("Resolving email '%s' to YT user name", youTubeEmail));
      youTubeName = youTubeApiHelper.getCurrentUsername();
    } catch (ServiceException e) {
      log.log(Level.WARNING, "Unable to resolve :" + youTubeEmail + " to YT username", e);
      throw new JSONException(e);
    } catch (IOException e) {
      log.log(Level.WARNING, "Unable to resolve :" + youTubeEmail + " to YT username", e);
      throw new JSONException(e);
    }
    return youTubeName;
  }
View Full Code Here

            if (upper != null){
                rangeObj.put("upper", upper.intValue());
            }
            jObj.put("range", rangeObj);
         }else{
             throw new JSONException("Error occured in setRange.  Range Must be a Map with 'lower' and 'upper' key.");
         }
     }
View Full Code Here

    
     private void setLabels( JSONObject jObj, Object labels ) throws JSONException {
        
         if (labels == nullreturn;
         if ( !(labels instanceof List)){
             throw new JSONException("xLabels is ignored, must be List<String> or List<Map>");
         }
      if (((List)labels).size() == 0return;
        
         Object testLabel = ((List)labels).get(0);
         JSONArray labelArray = new JSONArray();
        
         if (testLabel instanceof Map){
             for(Map oneLabel : (List<Map>) labels ){
                JSONObject labelObj = new JSONObject();
                setJObjectStr(labelObj, "label", (String) oneLabel.get("label") );
                setJObjectStr(labelObj, "value", (String) oneLabel.get("value") );
                setJObjectStr(labelObj, "title", (String) oneLabel.get("title") );
                labelArray.put(labelObj);
             }
             jObj.put("labels", labelArray);
         }else
         if (testLabel instanceof String){
             for(String  oneLabel  : (List<String>) labels){
                labelArray.put(oneLabel);
            }
            jObj.put("labels", labelArray);
         }else{
             throw new JSONException("xLabels is ignored, must be List<String> or List<Map>");
         }
     }
View Full Code Here

                String type = json.getString("type");
                Object typeValue = json.get("value");

                if (type == null)
                {
                    throw new JSONException("missing type attribute in json metadata for key " + key);
                }
                if (typeValue == null)
                {
                    throw new JSONException("missing type value attribute in json metadata for key " + key);
                }

                Class<?> typeClass;
                try
                {
                    typeClass = Class.forName(type);
                }
                catch (ClassNotFoundException e)
                {
                    throw new JSONException("invalid type attribute (" + type + ") in json metadata for key "
                        + key);
                }

                if (typeValue instanceof JSONArray)
                {
View Full Code Here

        {
            return Short.valueOf(value);
        }
        else
        {
            throw new JSONException("invalid type (" + type + ") attribute in json metadata");
        }
    }
View Full Code Here

                Array.set(result, i, Short.valueOf(array.getString(i)));
            }
        }
        else
        {
            throw new JSONException("invalid type (" + type + ") attribute in json metadata");
        }  
        return result;
    }
View Full Code Here

    public void flush() throws JSONException {
        try {
            writer.flush();
        } catch (IOException e) {
            throw new JSONException(e);
        }
    }
View Full Code Here

    public void close() throws JSONException {
        try {
            writer.close();
        } catch (IOException e) {
            throw new JSONException(e);
        }
    }
View Full Code Here

        JSONTokener t = new JSONTokener(s);
        Object o = t.nextValue();
        if (o instanceof JSONObject) {
            return (JSONObject) o;
        } else {
            throw new JSONException(s + " couldn't be parsed as JSON object");
        }
    }
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.