Examples of JSONTokener


Examples of org.json.JSONTokener

            InputStream input = null;
            try {
                if (status == 200) {
                    input = httpMethod.getResponseBodyAsStream();
                    JSONObject obj = new JSONObject(new JSONTokener(new InputStreamReader(input)));
   
                    JSONArray bundleStatus = obj.getJSONArray("s");
   
                    int total = bundleStatus.getInt(0);
                    int active = bundleStatus.getInt(1);
View Full Code Here

Examples of org.json.JSONTokener

        return " ["+resultCode+"]";
      }

            input = method.getResponseBodyAsStream();

            JSONObject result = new JSONObject(new JSONTokener(new InputStreamReader(input)));
            JSONArray dataArray = (JSONArray) result.get("data");
            JSONObject firstElement = (JSONObject) dataArray.get(0);
            return " ["+firstElement.get("state")+"]";
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

Examples of org.json.JSONTokener

  @Override
  public DBObject getQuery() {
    DBObject dbObj = ((CollectionBase) getParent()).getQuery();

    try {
      dbObj = mergeJson(new JSONObject(new JSONTokener(queryStr)), dbObj);
      return dbObj;
    } catch (JSONException e) {
      // TODO: handle this better!
      System.out.println("Failed to parse query str.");
    }
View Full Code Here

Examples of org.json.JSONTokener

public class JSONUtils {

    public static JSONObject objectForString(final String input) throws JSONException {
        assert input != null;
        JSONTokener tok = new JSONTokener(input);
        return new JSONObject(tok);
    }
View Full Code Here

Examples of org.json.JSONTokener

                              Annotation[] annotations,
                              MediaType mediaType,
                              MultivaluedMap<String, String> httpHeaders,
                              InputStream entityStream) throws IOException, WebApplicationException {
        try {
            return new JSONArray(new JSONTokener(ProviderUtils
                .createReader(entityStream, mediaType)));
        } catch (JSONException e) {
            logger.error(Messages.getMessage("jsonFailReadJSONArray"));
            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
        }
View Full Code Here

Examples of org.json.JSONTokener

                               MediaType mediaType,
                               MultivaluedMap<String, String> httpHeaders,
                               InputStream entityStream) throws IOException,
        WebApplicationException {
        try {
            return new JSONObject(new JSONTokener(ProviderUtils.createReader(entityStream,
                                                                             mediaType)));
        } catch (JSONException e) {
            logger.error(Messages.getMessage("jsonFailReadJSONObject"));
            throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
        }
View Full Code Here

Examples of org.json.JSONTokener

     */
    public void testAcceptHeaderSet() throws JSONException, JAXBException {
        String s =
            client.resource(getBaseURI() + "/echoaccept").accept(MediaType.APPLICATION_JSON_TYPE)
                .get(String.class);
        JSONObject j = new JSONObject(new JSONTokener(s));
        assertEquals("echo: " + MediaType.APPLICATION_JSON, j.get("value"));

        s =
            client.resource(getBaseURI() + "/echoaccept").accept(MediaType.TEXT_XML)
                .get(String.class);
View Full Code Here

Examples of org.json.JSONTokener

                bw.flush();
        }
    }

    public static FunctionRequest decodeRequest(Reader r) throws IOException, JSONException {
        JSONTokener t = new JSONTokener(r);
        JSONObject jo = new JSONObject(t);
        String name = jo.getString("name");
        JSONArray args = jo.getJSONArray("args");
        String sheetName = (String) jo.opt("sheetName");
        JSONObject caller = (JSONObject) jo.opt("caller");
View Full Code Here

Examples of org.json.JSONTokener

        return new FunctionRequest(name, xargs, cref, sheetName);

    }

    public static XLoper decodeXLoper(Reader r) throws IOException, JSONException {
        JSONTokener t = new JSONTokener(r);
        JSONObject jo = new JSONObject(t);
        return decode(jo);
    }
View Full Code Here

Examples of org.json.JSONTokener

     * Method extracted from {@code org.json.JSONObject#JSONObject(JSONTokener)}
     *
     * @param jsonString
     */
    public void read(String jsonString) {
        final JSONTokener x = new JSONTokener(jsonString);
        char c;
        String key;

        if (x.nextClean() != '{') {
            throw new IllegalArgumentException(format("String '%s' is not a valid JSON object representation, a JSON object text must begin with '{'",
                                                      jsonString));
        }
        for (;;) {
            c = x.nextClean();
            switch (c) {
            case 0:
                throw new IllegalArgumentException(format("String '%s' is not a valid JSON object representation, a JSON object text must end with '}'",
                                                          jsonString));
            case '}':
                return;
            default:
                x.back();
                key = x.nextValue().toString();
            }

            /*
             * The key is followed by ':'. We will also tolerate '=' or '=>'.
             */
            c = x.nextClean();
            if (c == '=') {
                if (x.next() != '>') {
                    x.back();
                }
            } else if (c != ':') {
                throw new IllegalArgumentException(format("String '%s' is not a valid JSON object representation, expected a ':' after the key '%s'",
                                                          jsonString, key));
            }
            Object value = x.nextValue();

            // guard from null values
            if (value != null) {
                if (value instanceof JSONArray) { // only plain simple arrays in this version
                    JSONArray array = (JSONArray) value;
                    Object[] values = new Object[array.length()];
                    for (int i = 0; i < array.length(); i++) {
                        values[i] = array.get(i);
                    }
                    value = values;
                }

                // if the concrete implementation is not able to handle the property, set the custom field
                if (!handleProperty(key, value)) {
                    builder.setCustomField(key, value);
                }
            }

            /*
             * Pairs are separated by ','. We will also tolerate ';'.
             */
            switch (x.nextClean()) {
            case ';':
            case ',':
                if (x.nextClean() == '}') {
                    return;
                }
                x.back();
                break;
            case '}':
                return;
            default:
                throw new IllegalArgumentException("Expected a ',' or '}'");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.