Examples of JsonParser


Examples of org.json.simple.parser.JSONParser

  private ApnsPayloadBuilder builder;
  private JSONParser parser;

  @Before
  public void setUp() {
    this.parser = new JSONParser();
    this.builder = new ApnsPayloadBuilder();
  }
View Full Code Here

Examples of org.json.simple.parser.JSONParser

      System.exit(-1);
    }
   
    // parse training data into clusters
    Map<String, Clusters> clusterMembership = new HashMap<String, Clusters>();
    JSONParser parser = new JSONParser();
    try {
      JSONObject parseObj = (JSONObject) parser.parse(new FileReader(trainingFile));
      JSONObject topicObj = (JSONObject) parseObj.get("topics");
      Set<String> topics = topicObj.keySet();
      Iterator<String> topicIt = topics.iterator();
      while (topicIt.hasNext()) { // for each topic
        String topic = topicIt.next();
View Full Code Here

Examples of org.json.simple.parser.JSONParser

  public WriteResponse execWrite(HttpRequestAttributes httpAttributes, Type requestType,
      List<RequestValue> resIds, SqlResource sqlResource, String requestBody,
      RequestLogger requestLogger) throws SqlResourceException {
    final Handler handler = new Handler(httpAttributes, requestType, resIds, sqlResource, requestLogger);
    try {
      final JSONParser parser = new JSONParser();
      parser.parse(requestBody, handler);
    } catch (final ParseException exception) {
      throw new InvalidRequestException("Error parsing request body: " + exception.toString());
    }
    final SqlResourceException handlerException = handler.getHandlerException();
    if (handlerException != null) {
View Full Code Here

Examples of org.json.simple.parser.JSONParser

    // TODO, assume the url is a file path for now.
    java.nio.file.Path configFile = Paths.get(configFileUrl);
    java.nio.file.Path preferenceFile = Paths.get(preferenceFileUrl);
    try {
      JSONParser parser = new JSONParser();
      JSONObject configJsonObject =
          (JSONObject) parser.parse(this.utils.readFile(configFile));
      JSONObject preferenceJsonObject =
          (JSONObject) parser.parse(this.utils.readFile(preferenceFile));

      String isAllowTracking = mergeBooleanSetting(
          "allow-anonymous-usage-tracking",
          configJsonObject,
          preferenceJsonObject);
View Full Code Here

Examples of org.json.simple.parser.JSONParser

    Assert.assertEquals(sampler.getRate(), (0d + 1 + 2 + 3) / 4, 0.0001);
    value[0] = 4;
    sampler.sample();
    Assert.assertEquals(sampler.getRate(), (4d + 1 + 2 + 3) / 4, 0.0001);

    JSONObject json = (JSONObject) new JSONParser().parse(sampler.toJSONString());
    Assert.assertEquals(json.size(), 2);
    Assert.assertEquals(json.get("sampler"), sampler.getRate());
    Assert.assertEquals(json.get("size"), 4L);

    StringWriter writer = new StringWriter();
    sampler.writeJSONString(writer);
    writer.close();
    json = (JSONObject) new JSONParser().parse(writer.toString());
    Assert.assertEquals(json.size(), 2);
    Assert.assertEquals(json.get("sampler"), sampler.getRate());
    Assert.assertEquals(json.get("size"), 4L);
  }
View Full Code Here

Examples of org.json.simple.parser.JSONParser

      public String getValue() {
        return "foo";
      }
    };

    JSONObject json = (JSONObject) new JSONParser().parse(variableHolder.toJSONString());
    Assert.assertEquals(json.size(), 1);
    Assert.assertEquals(json.get("value"), "foo");

    StringWriter writer = new StringWriter();
    variableHolder.writeJSONString(writer);
    writer.close();
    json = (JSONObject) new JSONParser().parse(writer.toString());
    Assert.assertEquals(json.size(), 1);
    Assert.assertEquals(json.get("value"), "foo");
  }
View Full Code Here

Examples of org.json.simple.parser.JSONParser

    Assert.assertEquals(values[InstrumentationService.Timer.LAST_TOTAL], totalDelta, 20);
    Assert.assertEquals(values[InstrumentationService.Timer.LAST_OWN], ownDelta, 20);
    Assert.assertEquals(values[InstrumentationService.Timer.AVG_TOTAL], avgTotal, 20);
    Assert.assertEquals(values[InstrumentationService.Timer.AVG_OWN], avgOwn, 20);

    JSONObject json = (JSONObject) new JSONParser().parse(timer.toJSONString());
    Assert.assertEquals(json.size(), 4);
    Assert.assertEquals(json.get("lastTotal"), values[InstrumentationService.Timer.LAST_TOTAL]);
    Assert.assertEquals(json.get("lastOwn"), values[InstrumentationService.Timer.LAST_OWN]);
    Assert.assertEquals(json.get("avgTotal"), values[InstrumentationService.Timer.AVG_TOTAL]);
    Assert.assertEquals(json.get("avgOwn"), values[InstrumentationService.Timer.AVG_OWN]);

    StringWriter writer = new StringWriter();
    timer.writeJSONString(writer);
    writer.close();
    json = (JSONObject) new JSONParser().parse(writer.toString());
    Assert.assertEquals(json.size(), 4);
    Assert.assertEquals(json.get("lastTotal"), values[InstrumentationService.Timer.LAST_TOTAL]);
    Assert.assertEquals(json.get("lastOwn"), values[InstrumentationService.Timer.LAST_OWN]);
    Assert.assertEquals(json.get("avgTotal"), values[InstrumentationService.Timer.AVG_TOTAL]);
    Assert.assertEquals(json.get("avgOwn"), values[InstrumentationService.Timer.AVG_OWN]);
View Full Code Here

Examples of org.json.simple.parser.JSONParser

   * @return the parsed JSON object.
   * @throws IOException thrown if the <code>InputStream</code> could not be JSON parsed.
   */
  private static Object jsonParse(HttpURLConnection conn) throws IOException {
    try {
      JSONParser parser = new JSONParser();
      return parser.parse(new InputStreamReader(conn.getInputStream()));
    }
    catch (ParseException ex) {
      throw new IOException("JSON parser error, " + ex.getMessage(), ex);
    }
  }
View Full Code Here

Examples of org.json.simple.parser.JSONParser

      conn.connect();
      InputStream in = conn.getInputStream();
      BufferedReader reader = new BufferedReader(
          new InputStreamReader(in));
      String jsonText = reader.readLine();
      JSONParser parser = new JSONParser();
      ContainerFactory containerFactory = new ContainerFactory() {
        public List creatArrayContainer() {
          return new LinkedList();
        }

        public Map createObjectContainer() {
          return new LinkedHashMap();
        }

      };

      try {
        Map json = (Map) parser.parse(jsonText, containerFactory);
        Iterator iter = json.entrySet().iterator();
        while (iter.hasNext()) {
          Map.Entry result = (Map.Entry) iter.next();
          if (result.getKey().equals("Results")) {
            LinkedHashMap resultHashMap = (LinkedHashMap) result
View Full Code Here

Examples of org.mozilla.javascript.json.JsonParser

    return (String) NativeJSON.stringify(cx, scope, object, null, null);
  }

  public Object parse(String string) {
    try {
      return new JsonParser(cx, scope).parseValue(string);
    } catch (ParseException e) {
      e.printStackTrace();
    }
    // return (ScriptableObject) NativeJSON.parse(cx, scope, string, null);
    return string;
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.