Package org.json

Examples of org.json.JSONTokener


    static public JSONObject evaluateJsonStringToObject(String s) throws JSONException {
        if( s == null ) {
            throw new IllegalArgumentException("parameter 's' should not be null");
        }
        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


            throw new JSONException(s + " couldn't be parsed as JSON object");
        }
    }

    static public JSONArray evaluateJsonStringToArray(String s) throws JSONException {
        JSONTokener t = new JSONTokener(s);
        Object o = t.nextValue();
        if (o instanceof JSONArray) {
            return (JSONArray) o;
        } else {
            throw new JSONException(s + " couldn't be parsed as JSON array");
        }
View Full Code Here

    public Object call(Properties bindings, Object[] args) {
        if (args.length >= 1) {
            Object o1 = args[0];
            if (o1 != null) {
                try {
                    return new JSONTokener(o1.toString()).nextValue();
                } catch (JSONException e) {
                    return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " failed: " + e.getMessage());
                }
            }
        }
View Full Code Here

                JSONArray jsonKeys = json.optJSONArray(Constants.FL_KEYS);
                props = json.optJSONObject(Constants.FL_SCHEMA);
                keys = ClientUtils.jsonArrayAsList(jsonKeys);
            } else {
                InputStream stream = r.getStream();
                JSONTokener tokens = new JSONTokener(new InputStreamReader(stream));

                // suck in the first object from the stream, which is the schema
                // and give the rest to the streamed keys collection
                props = new JSONObject(tokens).optJSONObject(Constants.FL_SCHEMA);
                keys = new StreamedKeysCollection(tokens);
View Full Code Here

                JSONArray jsonKeys = json.optJSONArray(Constants.FL_KEYS);
                props = json.optJSONObject(Constants.FL_SCHEMA);
                keys = ClientUtils.jsonArrayAsList(jsonKeys);
            } else {
                InputStream stream = r.getStream();
                JSONTokener tokens = new JSONTokener(new InputStreamReader(stream));

                // suck in the first object from the stream, which is the schema
                // and give the rest to the streamed keys collection
                props = new JSONObject(tokens).optJSONObject(Constants.FL_SCHEMA);
                keys = new StreamedKeysCollection(tokens);
View Full Code Here

        Object json = marshall(state, o);
        return json.toString();
    }

    Object fromJSON(String s) throws UnmarshallException {
        JSONTokener tok = new JSONTokener(s);
        Object json;
        try {
            json = tok.nextValue();
        } catch (ParseException e) {
            throw new UnmarshallException("couldn't parse JSON");
        }
        SerializerState state = new SerializerState();
        return unmarshall(state, null, json);
View Full Code Here

    PrintWriter pw = new PrintWriter(sw);
    KR2RMLRDFWriter outWriter = new JSONKR2RMLRDFWriter(pw, karma.getBaseURI());
    ContextIdentifier contextId = karma.getContextId();
    if (contextId != null) {
      try {
        JSONObject obj = new JSONObject(new JSONTokener(contextId.getLocation().openStream()));
        ((JSONKR2RMLRDFWriter)outWriter).setGlobalContext(obj, contextId);
        atId = ((JSONKR2RMLRDFWriter)outWriter).getAtId();
      }
      catch(Exception e)
      {
View Full Code Here

          req.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getReturnURL());
          req.addBodyParameter("grant_type", "authorization_code");
         
          String responce = req.send().getBody();

          JSONTokener tokener = new JSONTokener(responce);
          try {
              JSONObject root = new JSONObject(tokener);
              String access_token = root.getString("access_token");

              String token = OAuthEncoder.decode(access_token);
View Full Code Here

    pw.println("]");
    pw.close();
  }
 
  private static void processJSON(File file, MapReduceDriver<Writable, Text, Text, Text, Text, Text> mapReduceDriver) throws JSONException, FileNotFoundException {
    JSONTokener tokener = new JSONTokener(new FileInputStream(file));
    char c = tokener.nextClean();
    if (c == '[') {
      while (true) {
        Object o = tokener.nextValue();
        mapReduceDriver.addInput(new BytesWritable(), new Text(o.toString()));
        char tmp = tokener.nextClean();
        if (tmp == ']')
          break;
      }
    }
  }
View Full Code Here

      String contextName = "context/events_context.json";
      logger.info("Loading json file: " + filename);
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      File contextFile =  new File(getTestResource(contextName).toURI());
      JSONTokener token = new JSONTokener(new FileInputStream(contextFile));
      ContextIdentifier contextId = new ContextIdentifier("events-context", contextFile.toURI().toURL());
      JSONKR2RMLRDFWriter writer = new JSONKR2RMLRDFWriter(pw);
      writer.setGlobalContext(new JSONObject(token), contextId);
      RDFGeneratorRequest request = new RDFGeneratorRequest("events-model", filename);
      request.setInputFile(new File(getTestResource(filename).toURI()));
View Full Code Here

TOP

Related Classes of org.json.JSONTokener

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.